Hi Nifras,

Uploading base64 encoded string rather than the binary file has some
disadvantages.

   - Encoding to base64 is not a light-weight task. Especially for mobile
   devices it can be very painful. Also for large files, web browser
   might freeze or even crash [1].
   - Usually base64 encoded string is larger than its binary file about 33%
   [2] [3]. So uploading base64 encoded string consumes more bandwidth than
   uploading the binary file.
   - In the server-side, reading a file as a base64 encoded string loads
   the whole file to the memory (RAM) once which is a bad practice. But if you
   upload a binary file, then you can get a file stream to that (
   uploadedFile.getStream()) and can read the file from that stream safely.
   - Web browsers are optimized to handle uploading large files, but not
   base64 strings.


I also took the liberty to answer your StackOverflow question [4].

[1]
http://stackoverflow.com/questions/16761927/aw-snap-when-data-uri-is-too-large
[2]
http://stackoverflow.com/questions/16331215/can-i-make-image-upload-faster-using-base64-encoding-in-android
[3]
http://davidbcalhoun.com/2011/when-to-base64-encode-images-and-when-not-to/
[4] http://stackoverflow.com/a/32657419/1577286

Thanks.

On Fri, Sep 18, 2015 at 7:37 PM, NIFRAS ISMAIL <[email protected]>
wrote:

> Ya sajith, but in my assumption if we convert the image into base64
> encoding and post as string is take some how efficient way for direct image
> upload rather than file upload.
>
> Does this make any seance?
> On Sep 18, 2015 10:40 AM, "Sajith Ariyarathna" <[email protected]> wrote:
>
>> Hi Nifras,
>>
>> You can get multiple uploaded-files inside your Jaggery code using
>> request.getAllFiles() function. e.g.
>>
>> var files = request.getAllFiles();   // returns <name, File> map
>> for(var name in files) {
>>
>> if(files.hasOwnProperty(name)) {
>>
>> var file = files[name];
>>
>> // do something with file
>>
>> }
>>
>> }
>>
>>
>> Thanks.
>>
>> On Fri, Sep 18, 2015 at 7:08 AM, NIFRAS ISMAIL <[email protected]>
>> wrote:
>>
>>> Hi Sajith,
>>> Thank you for the guide.
>>> So we can add multiple files upload from this stream.
>>>
>>> Regards.
>>> *M. Nifras Ismail*
>>> [image: LinkedIn] <http://lk.linkedin.com/pub/nifras-ismail/54/343/94b>
>>>
>>>
>>>
>>> On Fri, Sep 18, 2015 at 12:32 AM, Sajith Ariyarathna <[email protected]>
>>> wrote:
>>>
>>>> Hi Nifras,
>>>>
>>>> request.getFile("myFile") does not represent a physical file, rather
>>>> it represent a stream to the uploaded file. Hence you cannot "move" it
>>>> using .move("...") function. If you want to save the uploaded file,
>>>> then use the following code snippet.
>>>>
>>>> var uploadedFile = request.getFile("myFile");
>>>> var savedFile = new File("/path/to/save/location/" +
>>>> uploadedFile.getName());
>>>> savedFile.open('w');
>>>> savedFile.write(uploadedFile.getStream());
>>>> savedFile.close();
>>>>
>>>>
>>>> Thanks.
>>>>
>>>> On Thu, Sep 10, 2015 at 2:41 PM, NIFRAS ISMAIL <[email protected]>
>>>> wrote:
>>>>
>>>>> Hi All,
>>>>> Do we upload images to the server directly using Jaggery JS?
>>>>> http://stackoverflow.com/a/32497617/2672566
>>>>>
>>>>> Regards.
>>>>> *M. Nifras Ismail*
>>>>> [image: LinkedIn]
>>>>> <http://lk.linkedin.com/pub/nifras-ismail/54/343/94b>
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Dev mailing list
>>>>> [email protected]
>>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Sajith Ariyarathna
>>>> Software Engineer; WSO2, Inc.;  http://wso2.com/
>>>> mobile: +94 77 6602284, +94 71 3951048
>>>>
>>>
>>>
>>
>>
>> --
>> Sajith Ariyarathna
>> Software Engineer; WSO2, Inc.;  http://wso2.com/
>> mobile: +94 77 6602284, +94 71 3951048
>>
>


-- 
Sajith Ariyarathna
Software Engineer; WSO2, Inc.;  http://wso2.com/
mobile: +94 77 6602284, +94 71 3951048
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to