Slava Balabanov
Posts: 0
Joined: Thu Apr 17, 2014 4:35 pm

Upload image from phone gallery

Hi,
I'm trying to upload an image file to the DB file collection. What i do is: Select an image from the phone gallery using Camera service and upload it.
I've used the following topic for help:
https://getsatisfaction.com/apperyio/...
My upload script is the following:
precode
function dataURItoBlob(dataURI) {
var byteString = atob(dataURI.split(',')[1]);
var ab = new ArrayBuffer(byteString.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString&#46;length; i++) {
ia = byteString&#46;charCodeAt(i);
}
return new Blob([ab], {type: 'image/jpeg'});
}
function upload(dbBase64) {
&#47;&#47; Generate a unique name
var userId = localStorage&#46;getItem('userId');
var dishName = localStorage&#46;getItem('toAddDishName');
var fileName = dishName + userId;

Code: Select all

 var serverUrl = 'https:&#47;&#47;api&#46;appery&#46;io/rest/1/db/files/' + fileName; 
 var f = dataURItoBlob(dbBase64); 

 $&#46;ajax({ 
 type: "POST", 
             beforeSend: function(request) { 
                 request&#46;setRequestHeader("X-Appery-Database-Id", Testeo_settings['database_id']); 
                 request&#46;setRequestHeader("X-Appery-Session-Token", localStorage&#46;getItem('userToken')); 
                 request&#46;setRequestHeader("Content-Type", 'image/jpeg'); 
             }, 
             url: serverUrl, 
             data: f, 
             processData: false, 
             contentType: false, 
             success: function(data) { 
                 &#47;&#47; We uploaded the image to the server&#46; Now put it in the table&#46; 
                 var uploadedFileName = data&#46;filename;                     

                 localStorage&#46;setItem('toAddImageFileName', uploadedFileName); 
             }, 
 error: function(xhr, textStatus, error) { 
  alert("error"); 
                 console&#46;log(xhr&#46;statusText); 
  console&#46;log(textStatus); 
  console&#46;log(error); 
 } 
}); 

}
/code/pre

the codedbBase64/code variable is the Base64 data that i get back from the camera service.
When i try to upload the image i get "Bad request" error
Am i doing something wrong?

I've also seen that you've updated the file upload tutorial but i thing i cannot use the input method as my data has to come from the phone gallery

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Upload image from phone gallery

Hello,

Could you also attach screen shot with error?

Slava Balabanov
Posts: 0
Joined: Thu Apr 17, 2014 4:35 pm

Upload image from phone gallery

I print all the variables on the error event (the status text, error).. It just says "bad request".. Nothing else, so I don't really know what to look for. Maybe the xhr object can contain some other info?
But I actually think that it has something to do with the image data because when I do the same with an input tag (as shown in the other thread that I took reference from) then it works

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Upload image from phone gallery

Hi Slava, what device are you using? Have you tried to debug it on the device?

Slava Balabanov
Posts: 0
Joined: Thu Apr 17, 2014 4:35 pm

Upload image from phone gallery

This is the message that i get when using the device, because i can only use the camera service on the device. I look at the console through the Weinre.
Using Nexus 5

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

Upload image from phone gallery

Hi Slava,

Could you please share your app with a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a and tell us its name?

Slava Balabanov
Posts: 0
Joined: Thu Apr 17, 2014 4:35 pm

Upload image from phone gallery

Hi,
Its already shared. Its called Plate-O.
The is relevant for the upload is uploadImage if I recall and the page is AddDish

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

Upload image from phone gallery

Hi Slava,

What are your test credentials?

Slava Balabanov
Posts: 0
Joined: Thu Apr 17, 2014 4:35 pm

Upload image from phone gallery

The process is: login with user 't@t' and password '123'
Press Add Dish on the right of the footer.
Choose anything from the lists 2 times
On the device,press the picture box and choose gallery.
Pick an image and then press approve button on right of the header.
For the PC browser it's the same only there is a pick image button and upload PC button

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Upload image from phone gallery

Hello Slava,

Thank you for information. We will test it, but testing might take some time.

Return to “Issues”