Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ricardoboss opened this issue Mar 22, 2024 · 3 comments · Fixed by #213
Closed

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

ricardoboss opened this issue Mar 22, 2024 · 3 comments · Fixed by #213
Assignees
Labels
enhancement New feature or request Standard GitHub label Issue caused by core project dependency modules or library

Comments

@ricardoboss
Copy link
Contributor

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
Copy link
Member

baywet commented Mar 22, 2024

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?

@baywet baywet added enhancement New feature or request Standard GitHub label Issue caused by core project dependency modules or library labels Mar 22, 2024
@ricardoboss
Copy link
Contributor Author

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

@ricardoboss
Copy link
Contributor Author

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

@github-project-automation github-project-automation bot moved this from Todo to Done in Kiota Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Standard GitHub label Issue caused by core project dependency modules or library
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants