I’m trying to upload my server an image from the gallery on the device. My code works fine when I take a new photo with your phone and upload. But when I select not working. The URL is incorrect or invalid. However I do not get error when I try uploading this. I’ll let my code
This is a factory i created for uploading images. Make sure you have the file-transfer plugin installed. What does your PHP script look like? I will post simple PHP below that works with this factory.
.factory('PhotoUpload', ['$q', 'URLS', function ($q, URLS) {
return {
upload: function (imgURI, fileName) {
var q = $q.defer();
function win(r) {
console.log(JSON.stringify(r));
q.resolve(r.response);
}
function fail(e) {
console.log(JSON.stringify(e));
q.reject(e);
}
var uri = encodeURI(URLS.photoUpload);
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=fileName;
options.mimeType="image/jpeg";
var ft = new FileTransfer();
ft.upload(imgURI, uri, win, fail, options);
return q.promise;
}
};
}]) // ********** end PhotoUpload factory **********
Thanks for your help !, the problem that I have is that when you select an image from my device, the URL to the image does not raise it, is invalid and is not an image. But if I upload an image just taken with the device I have no problems.
Not sure if this is the problem, but according to the file-transfer plugin docs, the encodeURI(server) and $scope.photo seem to be reversed. The image URI should be first and the server URI should be second.
@rgecy It did not work reverse the values, throws an error. I am using the image that rescued the same cell and it works. But not upload it to the server. Sera can miss some of the URL of the image?
If that doesnt work, it has to be the version of the plugin you are using. Are you building it with Ionic CLI as well using ‘ionic build android’ command?
Only option is the plugin. Remove the old plugin using cordova plugin remove org.apache.cordova.camera
and add it back using new command cordova plugin add cordova-plugin-camera