This is a migrated thread and some comments may be shown as answers.

sending an image file to web service

5 Answers 187 Views
Apache Cordova
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michael
Top achievements
Rank 1
Michael asked on 24 Jan 2014, 04:53 PM
we want to have a feature where the user takes a photo and then that photo is sent to a web service to be stored.

We are using:

function cameraApp () {};

cameraApp.prototype={
    _pictureSource: null,
    _destinationType: null,
........

to get the picture. We can get:  destinationType: cameraApp._destinationType.FILE_URI,
or:   destinationType: cameraApp._destinationType.DATA_URL

That works great. We display the output in an IMG tag, either way. The issues all seem to be with the sending part.. We tried:             ft.upload(imageURI, encodeURI("http://service.etc.etc/etc/service"), win, fail, options);

with any number of different configurations, etc. It doesn't do anything. It returns error code 1 or 3, and has never reached the server or returned the service response.

we tried passing the URI along to let the service to let it access the file, but then we have all kinds of issues about unable to resolve URI, etc.

this:

        var formData = new FormData();
        
        formData.append("myfile", blob, imagefilename);
        var request = new XMLHttpRequest();
        request.open("POST", "http://service..etc.etcetc");
        request.send(formData);

works perfectly, just - not on any mobile devices. works great in the simulator, but thats it.

We seem to be running out of ideas. Obviously, any number of mobile apps have this capability. So, what have others done successfully? This seems like it ought to be simple.

5 Answers, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 1
answered on 24 Jan 2014, 09:40 PM
Okay, very slight progress:

Using:             ft.upload(imageURI, encodeURI("http://service.etc/etc/etc"), win, fail, options, true);

(Just added ", true" into it and everything sends fine...)

works, BUT - only on iOS and only for retrieving photos from the photo library. Taking a new photo fails. I believe this is because it is saved into a temp directory and the URI it tries to send is no good.

So, how can we move the image into permanent storage, and what about android? android just gives error code 1 and 3. which are not errors from the server. the ft.upload itself is failing.
0
Michael
Top achievements
Rank 1
answered on 28 Jan 2014, 10:35 PM
The solution to all of these issues was just this:

            destinationType: that._destinationType.FILE_URI,
            encodingType : navigator.camera.EncodingType.JPEG, 
            quality: 40,
            targetWidth: 500,
            targetHeight: 500,
            saveToPhotoAlbum: 1

and setting the extra 'true' parameter on the upload...
0
Kristian D. Dimitrov
Telerik team
answered on 29 Jan 2014, 03:03 PM
Hello Michael,

Thanks for sharing your solution.

We noticed that our FileTransfer sample has only download functionality and we plan to extend it  to demonstrate how to upload files as well.

Regards,
Kristian D. Dimitrov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Michael
Top achievements
Rank 1
answered on 29 Jan 2014, 03:31 PM
There seems to be a restriction on file size/dimensions. We couldn't send photos taken via the app without specifying the dimension settings. Curiously, those same photos, if selected from the photo library, would not send unless we again specified the dimensions; though, photos taken directly through the phone's camera program will send via photo library selection regardless of specification. 
0
Steve
Telerik team
answered on 31 Jan 2014, 01:17 PM
Hello Michael,

I think this is required due to the fact that photos selected from the device's gallery are not downscaled to a lower quality, even if a quality parameter is specified.

Regards,
Steve
Telerik
Icenium is now Telerik AppBuilder, and is part of the Telerik Platform. For more information on the new name, and to learn more about the Platform, register for the free online keynote and webinar on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT)
Tags
Apache Cordova
Asked by
Michael
Top achievements
Rank 1
Answers by
Michael
Top achievements
Rank 1
Kristian D. Dimitrov
Telerik team
Steve
Telerik team
Share this question
or