How can I have the user upload their own photo and have that photo stored on the database so that each user can have his

This forum contains topics that were moved from Get Satisfaction
Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

How can I have the user upload their own photo and have that photo stored on the database so that each user can have his

Post by Joe Sharples »

Hi Yurii,
Thank you for you're time and detailed description, it has helped a lot.
just one more quick question.

I followed the steps and I get the result:
[{"success":{"filename":"bd7d7d8a-b449-4de0-a228-46e18fd5c857.myFile.png","fileurl":"https://api.appery.io/rest/1/db/files..."}}]

how would I save the "fileurl" to localstorage from this result?

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

How can I have the user upload their own photo and have that photo stored on the database so that each user can have his

Post by Yurii Orishchuk »

Hi Joe,

For example you can add "success" js event handler to this service with following JS code:

pre

for(var i = 0; i < data&#46;length; i++)
localStorage&#46;setItem("lsvName", data&#46;fileurl);

/pre

Regards.

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

How can I have the user upload their own photo and have that photo stored on the database so that each user can have his

Post by Joe Sharples »

Hi Yurii,

I tried your code on success:
Image

it didnt work.
I added, console.log("fileurl success test");
this didnt show in the console.

so i tried adding the code to success in the js on button click:

pre

var fileName = "myFile&#46;png";
var FDU = fileDataUrl64;
var FDUreplaced = FDU&#46;replace('data:image/jpeg;base64,','');

var base64Content = FDUreplaced;
var fileBlob = b64toBlob(base64Content, "image/png");
var data = new FormData();
data&#46;append(fileName, fileBlob);
var onSuccess = function(data){

Code: Select all

 for(var i = 0; i < data&#46;length; i++){ 
 localStorage&#46;setItem("TestfileURL", data[i]&#46;fileurl); 
 } 

alert(JSON&#46;stringify(data));
};
&#47;&#47;Where "uploadService2" is your updload service datasource name&#46;
uploadService2&#46;execute({
'allowDataModification': false,
'processData': false,
'body': {data: data},
'cache': false,
'success': onSuccess
});
/pre

after button click, "TestfileUrl" local storage is "undefined".

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

How can I have the user upload their own photo and have that photo stored on the database so that each user can have his

Post by Joe Sharples »

but the alert still showed the file uploading successfully

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

How can I have the user upload their own photo and have that photo stored on the database so that each user can have his

Post by Joe Sharples »

Is there a limit to the file size?

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

How can I have the user upload their own photo and have that photo stored on the database so that each user can have his

Post by Yurii Orishchuk »

Hi Joe,

Please show us browser debugger network tab where we can see request/response on this upload service.

Thanks.

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

How can I have the user upload their own photo and have that photo stored on the database so that each user can have his

Post by Joe Sharples »

figured it out!

it should have been:
codelocalStorage&#46;setItem("TestfileURL", data&#46;success&#46;fileurl);
/code

not:
code
localStorage&#46;setItem("TestfileURL", data&#46;fileurl);/code

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

How can I have the user upload their own photo and have that photo stored on the database so that each user can have his

Post by Joe Sharples »

Is there an easy way to reduce the image quality?

The image a user uploads is only displayed at a thumbnail size of around 80px wide.
The average image upload from the device camera is around 2.5-4MB. It doesnt need to be this large when only viewed with an 80px width.

how can I change the file size or image quality?

Thanks for all your help.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

How can I have the user upload their own photo and have that photo stored on the database so that each user can have his

Post by Yurii Orishchuk »

Hi Joe,

Yes, you can set this image into canvas and then make needed manipulations(for example resize) and get base64 source of this changed image.

Please read more details here: http://stackoverflow.com/questions/23...

Regards.

Post Reply