microsoft / kiota-abstractions-dotnet

Abstractions library for the Kiota generated SDKs in dotnet
https://aka.ms/kiota/docs
MIT License
24 stars 21 forks source link

Multipart body is missing the ability to add a filename #212

Closed ricardoboss closed 3 months ago

ricardoboss commented 3 months ago

Hi there,

I am trying to use Multipart and AddOrReplacePart(string, string, Stream) to upload files to my ASP.NET API. The API is unable to bind the submitted values to an IFormFile field.

After some trial-and-error I found out that it is because the request generated by kiota is missing the filename field in the Content-Disposition header.

I had to "hack" it in using this:

multipartBody.AddOrReplacePart("Screenshot\"; Filename=\"" + filename, contentType, stream);

Notice the \" to hijack the " from the WriteStringValue call in MultipartBody.

Do you plan to add support for adding parts with filenames/custom content-disposition values?

baywet commented 3 months ago

Hi @ricardoboss Thanks for using kiota and for reaching out. This is something we originally had not planned for. For reference, the header is written here. https://github.com/microsoft/kiota-abstractions-dotnet/blob/03026f728ac41c3398600d3f7406f7be123a9e46/src/MultipartBody.cs#L116 It should be fairly easy to add an optional parameter for the filename here https://github.com/microsoft/kiota-abstractions-dotnet/blob/03026f728ac41c3398600d3f7406f7be123a9e46/src/MultipartBody.cs#L35

And update the data structures to carry that information around until it comes time to write the body.

Is this something you'd be interested in submitting a pull request for?

ricardoboss commented 3 months ago

Sure, I'll take a look when I got time :)

ricardoboss commented 3 months ago

@baywet I think I found a good solution. Let me know what you think!