This question is locked. New answers and comments are not allowed.
Hi there -
I have tried just about every way I can find in the documentation and in these forums to send an image that I have just taken with my device camara.
I get my users photo with the following code:
I then wait for a success callback of a confirmation dialog and trigger the following:
Every time server responds with: An error has occured: Code = 1.
I have tried selecting an image from the photo library to see if that makes any difference but it did not. Also to note my file path of my image from camara is "file:///storage/emulated/0/Android/data/me.anchorman.anchor/cache/1416220390031.jpg". Is this correct?
Any help would be much appreciated.
Thanks.
I have tried just about every way I can find in the documentation and in these forums to send an image that I have just taken with my device camara.
I get my users photo with the following code:
navigator.camera.getPicture(onSuccess, onFail, {
quality: 100,
targetWidth : 500,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMARA
});
function
onSuccess(imageData) {
// hide camara initate button and replace with image from camara
var
image = document.getElementById(
'otherphoto'
);
var
other = document.getElementById(
'nophoto'
);
image.src = imageData;
image.style.display =
'block'
;
other.style.display =
'none'
;
// Set the image from camara to my global image object
theImage =
new
Object();
theImage = imageData;
// resolve filename and set global filename variable
window.resolveLocalFileSystemURL(imageData,
function
(fileEntry){
fileName = fileEntry.name;
},
function
(error){
console.log(
'about to resolve this files errors'
);
console.log(error.code);
});
}
function
onFail(message) {
alert(
'Failed because: '
+ message);
}
I then wait for a success callback of a confirmation dialog and trigger the following:
//set upload options
var
options =
new
FileUploadOptions();
options.fileKey =
"file"
;
options.fileName = fileName.substr(fileName.lastIndexOf(
'/'
)+1);;
options.mimeType =
"image/jpeg"
;
options.params = {
text : text
}
options.headers = {
'Authorization'
: token
}
function
win(r) {
console.log(
"Code = "
+ r.responseCode.toString() +
"\n"
);
console.log(
"Response = "
+ r.response.toString() +
"\n"
);
console.log(
"Sent = "
+ r.bytesSent.toString() +
"\n"
);
}
var
fail =
function
(error) {
// error.code == FileTransferError.ABORT_ERR
alert(
"An error has occurred: Code = "
+ error.code);
console.log(
"upload error source "
+ error.source);
console.log(
"upload error target "
+ error.target);
}
var
ft =
new
FileTransfer();
ft.upload(theImage, encodeURI(anchorUrl +
'items'
), win, fail, options);
Every time server responds with: An error has occured: Code = 1.
I have tried selecting an image from the photo library to see if that makes any difference but it did not. Also to note my file path of my image from camara is "file:///storage/emulated/0/Android/data/me.anchorman.anchor/cache/1416220390031.jpg". Is this correct?
Any help would be much appreciated.
Thanks.