You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* C# ASP.NET SERVER SIDE */publicboolUploadMyCoolFile([FromForm]intsomeFormElement,[FromForm]stringsomeOtherFormElement,[FromForm]IFormFilemyFileFormElement){// Deal with form elements}
Point is, by doing it like this, the web browser loads the file solely to send it, and therefore doesn't have to store the entire file within the web page's memory. It loads it, sends it, unloads it, which is the recommended way of sending files and avoids freezes and high memory usage for big files.
However, when using NSwag to generate a TS client to use that instead of manually creating my FormData, the following is generated:
Which defeats the point, it essentially puts all of IFormFile's properties as parameters, but that's not what we want here, if can't pass the native DOM File type to this.
Describe the solution you'd like
It would be nice if NSwag understood that any type that implements IFormFile on the C# side should become a File on the JS/TS side.
Describe alternatives you've considered
Loading the whole file on the web browser and uploading it as a byte array: very bad for huge files
Adding some kind of override to the OperationProcessorContext to replicate the desired behaviour: I couldn't find a way to do that, even using JsonObjectType.File gives some other type that would require loading the file beforehand
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
When I make a in a web page that includes uploading a file, I might want to send that file to my C# ASP.NET API using my NSwag-generated client.
Here's the deal, though: web standards will give you a
File
instance to work with, which you are meant to send throughFormData
to your endpoint.When using ASP.NET's
FromFormAttribute
, the file will automatically be parsed into aFormFile
instance (which implements theIFormFile
interface).As such, the following works:
Point is, by doing it like this, the web browser loads the file solely to send it, and therefore doesn't have to store the entire file within the web page's memory. It loads it, sends it, unloads it, which is the recommended way of sending files and avoids freezes and high memory usage for big files.
However, when using NSwag to generate a TS client to use that instead of manually creating my
FormData
, the following is generated:Which defeats the point, it essentially puts all of
IFormFile
's properties as parameters, but that's not what we want here, if can't pass the native DOMFile
type to this.Describe the solution you'd like
It would be nice if NSwag understood that any type that implements
IFormFile
on the C# side should become aFile
on the JS/TS side.Describe alternatives you've considered
OperationProcessorContext
to replicate the desired behaviour: I couldn't find a way to do that, even usingJsonObjectType.File
gives some other type that would require loading the file beforehandThe text was updated successfully, but these errors were encountered: