sending an image file to web service

6 posts, 0 answers
  1. Michael
    Michael avatar
    151 posts
    Member since:
    Jan 2012

    Posted 24 Jan 2014 Link to this post

    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.
  2. Michael
    Michael avatar
    151 posts
    Member since:
    Jan 2012

    Posted 24 Jan 2014 Link to this post

    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.
  3. Michael
    Michael avatar
    151 posts
    Member since:
    Jan 2012

    Posted 28 Jan 2014 Link to this post

    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...
  4. Kristian D. Dimitrov
    Admin
    Kristian D. Dimitrov avatar
    68 posts

    Posted 29 Jan 2014 Link to this post

    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.

  5. Michael
    Michael avatar
    151 posts
    Member since:
    Jan 2012

    Posted 29 Jan 2014 in reply to Kristian D. Dimitrov Link to this post

    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. 
  6. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 31 Jan 2014 Link to this post

    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)
Back to Top