Open robertcopper opened 6 years ago
I'm handling file uploads like this:
PKMultipartInputStream *body;
...
[body addPartWithName:name filename:originalFilename path:filepath contentType:contentType];
...
[theRequest setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[body length]] forHTTPHeaderField:@"Content-Length"];
I suggest that won't work. The encoded length of the UTF-8 stream depends upon the actual contents of the file. Base64 is guaranteed to be 4/3 * (the original length rounded up to a multiple of three).
Unless the length field refers to the length of the decoded data.
Apparently, it refers to the "transfer-length of the message-body". RFC 2616 section 14.13
https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
It's also apparently optional.
@jznadams
I did set the request length by your method for my revised demo app, but had not in my application's code. Our server apparently requires the parameter even if it's inaccurate.
I need to upload audio, video, and images as part of a multipart/form-data POST. These are best encoded in Base64.
The principal advantage is a predictable length. The request header requires a length. Is this the length of the encoded or the decoded data?
UTF-8 adds escape sequences to the data stream, which makes the length depend on the actual data, and not the size of the file.