Skip to content

C# ApiClient PrepareRequest FileParam ContentLenght problem #3555

Closed
@glecchi

Description

@glecchi
Description

Using a FormData request, in the method PrepareRequest of the ApiClient, when file is added to the request, RestSharp doesn't set the Content-Length.

foreach (var param in fileParams)
{
    request.AddFile(param.Value.Name,` param.Value.Writer, param.Value.FileName,    param.Value.ContentType);
}
Swagger-codegen version

Version 2.10.2

Suggest a Fix

At the time, the workaround i found was to modify the generated code and set the content length explicitly:

var index = 0;
foreach (var param in fileParams)
{
    request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
    request.Files[index++].ContentLength = param.Value.ContentLength;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions