Skip to content

Multipart uploading - wrong content length #939

Closed
@AlexSchoenfeld

Description

@AlexSchoenfeld

Hi,

I'm trying to get multipart uploading working with v105.2.3, but it seems there is something wrong with the Content-Length.

using (FileStream source = File.Open(path, FileMode.Open))
{
    RestSharp.RestRequest request2 = new RestSharp.RestRequest();
    request.Resource = $"/files/uploads/{UploadId}";
    request.Method = Method.POST;
    request.AddFile(filename, source.CopyTo, filename);
    request.AlwaysMultipartFormData = true;

    IRestResponse<UploadResponse> response2 = this.Client.Execute<UploadResponse>(request);
    if ((int)response2.StatusCode != 201)
    {
        throw new Exception(response2.StatusDescription);
    }
}

The response2 has this Error Message (it's in german and means Request was cancelled.):
Die Anfrage wurde abgebrochen: Die Anfrage wurde abgebrochen..

Inner Exception (Cannot close the stream until all bytes are written):
Stream kann nicht geschlossen werden, bevor alle Bytes geschrieben wurden.

In Fiddler I get this:

Request - Entity

Content-Length: 210
Content-Type: multipart/form-data; boundary=-----------------------------28947758029299

Response

HTTP/1.1 408 Request body incomplete
The request body did not contain the specified number of bytes. Got 159, expected 210

I need to use the Nuget package with this versions since I have other packages (like RestSharp.Newtonsoft.Json) that require this version.
Seems like the same problem here:
#742

Best regards,
Alex

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions