Hi,
I am trying to upload photo to the Files database, but I get a failure in ft.upload() in the code below. The error code is 3. I can't seem to find any issue with the code below. Any ideas?
It will be good to have a tutorial that shows how to upload a picture taken with the device camera to the Files database.
function takePhoto() {
// Retrieve image file location from specified source
navigator.camera.getPicture(uploadPhoto,
Code: Select all
function(message) {
alert('get picture failed');
}, {
quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
});
}
function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
Code: Select all
var params = {};
params.value1 = "X-Appery-Database-Id=...";
params.value2 = "X-Appery-Session-Token=" + localStorage.getItem("userSessionToken");
params.value3 = "Content-Type=application/jpeg";
options.params = params;
alert("Uploading photo....");
var ft = new FileTransfer();
var url = "[url=https://api.appery.io/rest/1/db/files/test.jpeg]https://api.appery.io/rest/1/db/files...[/url]"
ft.upload(imageURI, encodeURI(url), win, fail, options); // this fails with error code 3.
}
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
alert("Sent = " + r.bytesSent);
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
alert("upload error source " + error.source);
alert("upload error target " + error.target);
}
Thanks!
Vijay