Cordova File Transfer remove Multipart or Content-Disposition Header

前端 未结 4 738
暖寄归人
暖寄归人 2020-12-21 11:34

I managed to upload an image to my server using Cordova File Transfer plugin.

var img = 
var url = 

var o         


        
相关标签:
4条回答
  • 2020-12-21 11:56

    Please add headers to options

    var headers={'headerParam':'headerValue'};
    options.headers = headers;
    

    Just refer the example from GitHub.

    0 讨论(0)
  • 2020-12-21 12:02

    Based on the source code:

    boolean multipartFormUpload = (headers == null) || !headers.has("Content-Type");
    if (multipartFormUpload) {
      conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
    }
    

    You can find it is easy to disable the multipart header by setting a dummy header option in your javascript:

    options.headers = {"Content-Type":"dummy"}; // set it to something to avoid the plug-in append the header
    
    0 讨论(0)
  • 2020-12-21 12:04

    Took me awhile to figure this but this is the way I removed the Multipart Header. Here's the solution/work around.

    Open: \platforms\android\src\org\apache\cordova\filetransfer\FileTransfer.java

    Look for:

    sendStream.write(beforeDataBytes);
    totalBytes += beforeDataBytes.length;
    

    Comment away or delete these 2 lines. They are the code that adds the multipart header.

    Also remove:

    sendStream.write(tailParamsBytes);
    totalBytes += tailParamsBytes.length;
    

    This code adds a tail for the multipart header.

    I have done a MD5 checksum check and they are of the same now.

    0 讨论(0)
  • 2020-12-21 12:15

    Just put a 'Content-Type' in Headers.

    headers: A map of header name/header values. Use an array to specify more than one value. On iOS, FireOS, and Android, if a header named Content-Type is present, multipart form data will NOT be used. (Object)

    https://github.com/apache/cordova-plugin-file-transfer#example-with-upload-headers-and-progress-events-android-and-ios-only

    0 讨论(0)
提交回复
热议问题