facebook-csharp-sdk / facebook-winclient-sdk

Facebook SDK for Windows & Windows Phone
http://facebooksdk.net
Apache License 2.0
61 stars 139 forks source link

Incorrect number of bytes sent in multipart form data when FacebookMediaObjects or FacebookMediaStreams are used #86

Closed 0ats closed 9 years ago

0ats commented 9 years ago

Adding one or more FacebookMediaObjects or FacebookMediaStreams to the parameters collection of a Post method causes an extra newline (MultiPartNewLine) to be added prior to the final --boundary-- delimiter of the form data. In the case of Facebook's resumable (chunked) uploads, this causes the start_offset to be calculated incorrectly for the second chunk.

Repro: Post to /videos edge with parameters {upload_phase=start, file_size=FILE_SIZE}. Result will include upload_session_id [=USID] and start_offset [= 0] for first chunk. Post first chunk of size [=FIRST_CHUNK_SIZE] to /videos edge with parameters {upload_phase=transfer, upload_session_id=USID, start_offset=0}. Result will include start_offset for second chunk equal to FIRST_CHUNK_SIZE + 2.

Expected: The result of the second call should return a start_offset of FIRST_CHUNK_SIZE.

The extra 2 bytes appears to be from an extra MultiPartNewLine ("\r\n") being added just prior to the final --boundary-- delimiter of the multipart form data. Facebook receives a chunk 2 bytes larger than what was actually sent by the user.

This appears to be happening in FacebookClient.cs:PrepareRequest() line 571 in the master branch:

streams.Add(new MemoryStream(Encoding.UTF8.GetBytes(string.Concat(MultiPartNewLine, MultiPartFormPrefix, boundary, MultiPartFormPrefix, MultiPartNewLine))));