Hi all
Any advice in how to transfer image data from phone gap to rails?

I try to write small code,but that can not transfer image data.
below is samall corde(server address:192.168.100.242:3000
controller:photos action:up)

/////////////////////////////
rails :routes.rb//////////////////////////////
Store::Application.routes.draw do

get "photos/up"


//////////////////////////////rails
photos_controller.rb//////////////////////////////
class PhotosController < ApplicationController
def up
p "-------"
p params
end
end

//////////////////////////////phonegap
index.html//////////////////////////////




(function($) {
document.addEventListener("deviceready", function() {

$("#camera").click(function(){
navigator.camera.getPicture(
uploadPhoto
, function(error) {
alert("camera error");
}, {quality: 50, destinationType:
Camera.DestinationType.FILE_URI});
});

});
function uploadPhoto(imageURI) {
$("#image").attr("src", imageURI);
var options = new FileUploadOptions();
options.chunkedMode = false;
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')
+1);
options.mimeType="image/jpeg";

var params = new Object();
params.value1 = "test";
params.value2 = "param";

options.params = params;

var ft = new FileTransfer();
ft.upload(imageURI, "http://192.168.100.242:3000/photos/up",
win, fail, options);
}

function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}

function fail(error) {
alert("An error has occurred: Code = " = error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
})(jQuery);


Regards

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Ta_ni_ at Feb 26, 2012 at 5:09 am
    Has been resolved.
    I forget to add setting of ExternalHosts.
    to add new item (value = *) to PhoneGap.plist - ExternalHosts
    On 2月24日, 午前9:21, ta_ni_ wrote:
    Hi all
    Any advice in how to transfer image data  from phone gap  to rails?

    I try to write small code,but that can not transfer image data.
    below is samall corde(server address:192.168.100.242:3000
    controller:photos action:up)

    /////////////////////////////
    rails :routes.rb//////////////////////////////
    Store::Application.routes.draw do

    get "photos/up"

    //////////////////////////////rails
    photos_controller.rb//////////////////////////////
    class PhotosController < ApplicationController
    def up
    p "-------"
    p params
    end
    end

    //////////////////////////////phonegap
    index.html//////////////////////////////

    (function($) {
    document.addEventListener("deviceready", function() {

    $("#camera").click(function(){
    navigator.camera.getPicture(
    uploadPhoto
    , function(error) {
    alert("camera error");
    }, {quality: 50, destinationType:
    Camera.DestinationType.FILE_URI});
    });

    });
    function uploadPhoto(imageURI) {
    $("#image").attr("src", imageURI);
    var options = new FileUploadOptions();
    options.chunkedMode = false;
    options.fileKey="file";
    options.fileName=imageURI.substr(imageURI.lastIndexOf('/')
    +1);
    options.mimeType="image/jpeg";

    var params = new Object();
    params.value1 = "test";
    params.value2 = "param";

    options.params = params;

    var ft = new FileTransfer();
    ft.upload(imageURI, "http://192.168.100.242:3000/photos/up",
    win, fail, options);
    }

    function win(r) {
    console.log("Code = " + r.responseCode);
    console.log("Response = " + r.response);
    console.log("Sent = " + r.bytesSent);
    }

    function fail(error) {
    alert("An error has occurred: Code = " = error.code);
    console.log("upload error source " + error.source);
    console.log("upload error target " + error.target);
    }
    })(jQuery);

    Regards
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedFeb 24, '12 at 8:54a
activeFeb 26, '12 at 5:09a
posts2
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

Ta_ni_: 2 posts

People

Translate

site design / logo © 2022 Grokbase