-
-
Notifications
You must be signed in to change notification settings - Fork 747
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
[BUG] How to upload IFormFile within an object model using refit in .Net core #991
Comments
This is what I do... API Client
API signature
|
Hi natelaff, can you please tell me how would hit your refit method from .net core mvc action method and what if I have object to pass to web api and within that I have IFormFile property rather than calling API directly with single IFormFile property? |
I use something like var file = Request.Form.Files[0]; |
But would it require me to change IFormFile in my api controller? How I can pass new Refit.StreamPart(...) as property of my existing model. I don't wanna call separate api with just image rather I wanna pass it as a whole object within my original model. |
No, you can see my definitions of the client and the API method above. I use IFormFile in the API, and StreamPart in the client. EDIT: Oh, I see what you're saying. I don't know about that, I don't use uploads in a complex model. I have a separate Image upload API then post that URL with my object. |
Ok thanks natelaff, I think I am left with either two API calls or convert IFormFile into byte[] in model. If you know any other solution then please let me know. |
@dev-vkagrawal please if you solve this issue please share with me |
I have still not been able to make this work: //refit api
[Multipart]
[Post("/api/cluster/deploy")]
Task PostDeployAsync([AliasAs("file")] StreamPart stream);
//my backend controller
[HttpPost("deploy"), DisableRequestSizeLimit]
public async Task PostDeployAsync(IFormFile file)
{
//blazor code
<Blazorise.FileEdit Changed="@OnChanged" />
async Task OnChanged(FileChangedEventArgs e)
{
foreach (var file in e.Files)
{
var fs = file.OpenReadStream();
await _api.PostDeployAsync(new StreamPart(stream, file.Name, "application/zip", file.Name)); In my controller the |
Im on the same boat. I have a scenario where I need to send data to an api that consumes a model with an List. public class Class1{ [Multipart] The files dont seem to work unless I do a Post([AliasAs("Files")] IEnumerable files); |
Hi any update on supporting upload complex object which have IFormFile in it ? |
Same problem here. IFormFile is a part of another model. Doesn't work with refit. |
@DrLeh |
Hi,
Can anyone tell how to upload file of type IFormFile within an object in .Net Core. If model contains IFormFile type then it is not working. I have used [Multipart] attribute and can't replace IFormFile to something else as I have used that across entire project.
The text was updated successfully, but these errors were encountered: