0

I'm building a dart app using Cordova. According to cordova doc , I'm using FILE_URI to retrieve the image.

I'm using 'dart:js' to call my JS script where I have

 function loadPhotofromPhoneLibrary(onPhotoURISuccess,onFail) {
        // Retrieve image file location from specified source
        navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
            destinationType: destinationType.FILE_URI,
            sourceType: pictureSource.PHOTOLIBRARY });
}

In my dart code , how can post my image to the server from an imageURI, using HTTPRequest

  void onloadPhotoFromPhoneLibrary() {
    js.context.callMethod('loadPhotofromPhoneLibrary',[onPhotoURISuccess,onPhotoURIFail]);
  }

  void onPhotoURISuccess(imageURI) {
    // TODO: Here how to post imageURI as MULTIPART_FORM_DATA to Server :( ?
  }

  void onPhotoURIFail(message) {
    window.alert('Failed because: ' + message);
  }
bwnyasse
  • 591
  • 1
  • 10
  • 15
  • http://stackoverflow.com/questions/25742113/dart-post-with-multipart-form-data is about posting multipart form. I don't know what `imageURI` for `FILE_URI` is. – Günter Zöchbauer Mar 25 '16 at 06:50
  • 1
    I guess posting with the 'FormData' means that value is loaded in memory , ( data.append(key, value) ) . As cordova doc mention, https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-camera/index.html#cameragetpicture-errata , using DATA_URL is not recommanded. So I think I can't use the FormData ? If you look at this link http://gonzalo123.com/2013/10/28/taking-photos-with-a-phonegapcordova-application-and-uploading-them-to-the-server/ , you'll see that people use a cordova plugin 'FileTransfer' to do the job. I was looking a way to do it in Dart – bwnyasse Mar 25 '16 at 08:21
  • 1
    I've changed my approch. I wrote the file upload in pure JS with cordova transfer plugin like described here http://zacvineyard.com/blog/2011/03/upload-a-file-to-a-remote-server-with-phonegap . And my success callback is written in dart ( the function win(r) is the example ) . Like this , I'm able to use camera.getPicture and post image to the server. I don't anymore care about how to deal with the imageURI – bwnyasse Mar 29 '16 at 07:30

0 Answers0