Matthew Huang
Posts: 0
Joined: Mon Jun 09, 2014 11:06 am

How to resize data-uri image before sending to DB (update service) for web-app ?

Hi!

Using the code from this post:

https://getsatisfaction.com/apperyio/...

I can upload image to DB from desktop browser.
But when I try to upload image from phone browser to DB, only small image file can be uploaded successfully. Therefore, I need to resize the image before uploading.

To be more specific, referring to the following code, after I get "fileDataUrl"
( var fileDataUrl = e.target.result; ) ,
how do I resize "fileDataUrl" before saving it as local storage variable?

function previewFile() {
var previewContainer = $('table[dsid=preview]');
var fileName = $('[name=fileName]');
var fileContentType = $('[name=fileContentType]');

// make the preview container visible once a file was selected
previewContainer.toggle();
// set the file name
fileName.text(file.name);
fileContentType.text(file.type);
var reader = new FileReader();
reader.onloadend = function(e) {
var fileDataUrl = e.target.result;
localStorage.setItem("fileDataUrl", fileDataUrl);
//Set current avatar to the image component
Apperyio("profile_pic").attr("src", fileDataUrl);
//It will invoke your "restservice4" dataSource of "User_Info_update_service" service.
restservice4.execute();
};
reader.readAsDataURL(file);
}

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

How to resize data-uri image before sending to DB (update service) for web-app ?

Hello Matthew,

Please look at this link, information there should be useful: https://getsatisfaction.com/apperyio/...

Matthew Huang
Posts: 0
Joined: Mon Jun 09, 2014 11:06 am

How to resize data-uri image before sending to DB (update service) for web-app ?

I tried all the approaches from the link you referred to.
And only the following approach works perfectly for me.

Image

Suggestion: Guide future question-askers to this one, so they won't waste time testing every approaches to find the solution.

Return to “Issues”