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