Open jnnwnk opened 5 years ago
👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.
The team will review the labels and make any necessary changes.
I had this issue as well. I worked around it by changing the generated model files from byte[] to IFormFile and then using the helper function below to convert to byte[]
public byte[] getUploadedFile(IFormFile file)
{
byte[] result;
using (var memoryStream = new MemoryStream())
{
if (file != null)
{
file.CopyTo(memoryStream);
result = memoryStream.ToArray();
}
else
result = null;
}
return result;
}
@jwr456 could you please also provide the change of the model mustache for your workaround? Iam facing for this problem as well right now and have no idea how to solve it. Thanks
Hello guys, I'm having the same issue for generating the csharp client for Upload rest endpoint. I was wondering if this has been resolve, if so how should one correctly generate a csharp client object that uses IFormFile in the Dot 7 framework?
Description
I try to generate a ASP .NET Core server side library for file uploads. All examples I've seen so far are using the C# type
IFormFile
to receive file content. However if I declare an interface with content typemultipart/form-data
and a property of typestring
with formatbinary
(see yaml snippet) openapi generates a method parameter of type`
System.IO.Stream`. If I try uploading a file using this interface I am getting an exception:Am I missing something or is there any kind of workaround (make
System.IO.Stream
working or forcing openapi to useIFormFile
)?openapi-generator version
3.3.4
OpenAPI declaration file content or url
openapi.yaml
Command line used for generation
java -jar openapi-generator-cli-3.3.4.jar generate -i openapi.yaml -g aspnetcore --model-name-suffix DTO
Steps to reproduce
openapi.yaml
to call command line.FileUploadApiController
.http://127.0.0.1/api/upload
Related issues/PRs
There is a similar issue #1381 about problems with files on client side in C#. And also one about generation of byte/binary body in C# aspdotnet service side: #1327
Suggest a fix/enhancement
In my opinion best / easiest would be if the generated method uses
IFormFile
. Other options could be to make this some how configurable or to generate additional code to makeStream
work out of the box. I came acrose an example suggested on stackoverflow to makeStream
working, but I guess this is .NET Framework. Anyway I'v not tested it yet.