3

I have a Cordova app for iOS, which I'm now updating to support Android. I have most of the issues worked out, but the FileTransfer plugin is not including FileUploadOptions.params in the request. Everything works smoothly on iOS. With Android, the request is sent, and everything seems normal except the request that reaches the server has no form fields.

I have set a breakpoint just before calling the upload method, and the options.params object looks correct.

I'm testing with Android 4.4.3, Cordova 3.5, and FileTransfer plugin 0.4.4. The server is running Apache and has SSL enabled.

Here is my code:

var options = new FileUploadOptions();
options.chunkedMode = false;
options.mimeType = 'audio/mp4';
options.fileKey = 'file';
options.fileName = filename;
options.params = {
    'siteId': siteId,
    'name': nameFld.getValue(),
    'date': sqlDate,
    'length': Math.round(storyLength)
};
options.headers={'Authorize': token};

var ft = new FileTransfer();
ft.upload(path, url, uploadSuccess, uploadFail, options);

I found the same issue here, with no response: Phonegap fileTransfer upload doesn't POST params

UPDATE: Opened an issue for this here: https://issues.apache.org/jira/browse/CB-7171

Community
  • 1
  • 1
bjudson
  • 4,073
  • 3
  • 29
  • 46
  • I am facing a similar problem. The file upload is optional. So when there are not files attached. The params doesnt reach server. (But the header works). Do you know any way in which this can be sorted out? (without another angular http.post is being used ) – raj Dec 05 '16 at 15:49

3 Answers3

3

The key to making it work set the option.headers:

options.headers = {
    Connection: "close"
}

Phonegap File Transfer of picture fails on every other picture: Error code 3 with FileTransfer upload

Community
  • 1
  • 1
Varun Nath
  • 5,570
  • 3
  • 23
  • 39
  • Thanks for the tip, but this approach does not solve the problem. It appears to be a different issue than the one you linked to. Cordova consistently sends the request with the file, but no extra params. – bjudson Jul 24 '14 at 13:48
2

I got it working; it turns out I was wrong about the file being successfully transferred. Due to some confusion about the Android file system, I was using the wrong file path.

The plugin did not raise an error in the JavaScript console, and proceeded to make the request without data attached. Once I checked the error messages in the Dalvik Debug Monitor, I was able to track down the problem.

bjudson
  • 4,073
  • 3
  • 29
  • 46
-1

I can confirm, I have the same issue with the latest versions as you specified. One solution is apparently to use jquery.fileupload. I haven't tried it yet. But, will post if it is successful.!