adam griffin
Posts: 0
Joined: Tue May 21, 2013 8:44 pm

How can I upload base64 data as a file to the database?

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?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

How can I upload base64 data as a file to the database?

Hi Adam,

Please check if this solution is appropriate for you:
https://getsatisfaction.com/apperyio/...

adam griffin
Posts: 0
Joined: Tue May 21, 2013 8:44 pm

How can I upload base64 data as a file to the database?

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&quot 

     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"

adam griffin
Posts: 0
Joined: Tue May 21, 2013 8:44 pm

How can I upload base64 data as a file to the database?

This solution did not help

adam griffin
Posts: 0
Joined: Tue May 21, 2013 8:44 pm

How can I upload base64 data as a file to the database?

Can someone help me?? I even tried just calling "uploadPhoto" and get an error at "FileUploadOptions()" not defined

obullei
Posts: 0
Joined: Thu Jun 05, 2014 12:17 am

How can I upload base64 data as a file to the database?

Hello!

We are working on it.
I will let you know when have more information from developers team.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

How can I upload base64 data as a file to the database?

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.

Return to “Issues”