1

I'm building an Android app using Cordova.

I have a form with <input type="file" /> in it.

I would like to send an avatar image via PUT API method:

$.ajax({
  type: 'PUT',
  url: my_fancy_api_url,
  data:
    {avatar: url_to_avatar}
  }).done(function(resp){
  ...

If I send it via web api form everything works fine, but when I'm trying to send it via Cordova app it doesn't change/gets an error that avatar is not a file etc.

My question is: how to get local file url from file input? If I try file_input.value I get C:/fakepath..., but if I try file_input.files[0] or file_input.files[0].name it doesn't work either - how to get this dynamic path properly? What's the correct way of doing it?

All tutorials about cordova's file / filetransfer plugin has already known path to file, but I don't know how to get it properly.

lukaszkups
  • 5,790
  • 9
  • 47
  • 85
  • Are you providing option to thw user to select the image from anywhere in the device to be uploaded? Why cant you use file plugin for this? – Gandhi May 06 '16 at 10:06
  • I'm not sure if I understand it correctly - if I click on file input then the file manager appears and I can select files from the device - but after selecting how to get proper value from the file input? – lukaszkups May 06 '16 at 10:21
  • 1
    This link should help you get started - http://stackoverflow.com/questions/26735864/invoke-native-file-browser-using-phonegap – Gandhi May 06 '16 at 10:31

0 Answers0