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:
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: