I am trying to upload base64 data from an image. Create a file from it and upload it to my database. How can I do this? Is it possible?
I am trying to upload base64 data from an image. Create a file from it and upload it to my database. How can I do this? Is it possible?
Hi Adam,
Please check if this solution is appropriate for you:
https://getsatisfaction.com/apperyio/...
I created a function from the link's code:
code
function uploadBase64(data) {
Code: Select all
var file = new File(data);
uploadPhoto(data);
function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
options.fileKey = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg"
var params = {
headers: {
'X-Appery-Database-Id': "530dasde4e16aaaa4222e7",
//'X-Appery-Session-Token': localStorage.getItem('token')
'X-Appery-Session-Token':'050b21f5-d74c-4ddf-b785-e1764c8c138a'
}
};
options.params = params;
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI("https://api.appery.io/rest/1/db/files"), 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);
}
}
/code
Data is the base64 from another function. When I run the code from the link it says I must use the new operand for :
codevar file = File(data);/code
So I add the "new" operand
codevar file = new File(data);/code
It gives error: "Faile to construct 'File': Illegal constructor"
This solution did not help
Can someone help me?? I even tried just calling "uploadPhoto" and get an error at "FileUploadOptions()" not defined
Hello!
We are working on it.
I will let you know when have more information from developers team.
Hi Adam,
Where do you get this error, in browser? This code is supposed to work on device only (http://docs.phonegap.com/en/3.3.0/cor...). Please specify your device and OS version, and also Appery.io libraries version you use.