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

Question: Multipart form-data with Refit #930

Open
johnybaryah opened this issue May 23, 2020 · 10 comments
Open

Question: Multipart form-data with Refit #930

johnybaryah opened this issue May 23, 2020 · 10 comments

Comments

@johnybaryah
Copy link

johnybaryah commented May 23, 2020

Hi,

I have a dotnet core web api endpoint that takes a strongly typed object as argument

public class FileUploadArgs
{   
    public int Id { get; set; }
    public string Email { get; set; }
    public IFormFileCollection Files { get; set; }
}

Endpoint signature:

[HttpPost, Route("upload")]
public async Task<IActionResult> UploadFile([FromForm] FileUploadArgs args)

I call this method via HTTPIE on shell as

$ http -f POST localhost:5000/api/v3/file/upload Id='123456' Email='test@test.com' 'Files'@/mnt/c/apiloadtest/2124545.pdf x-api-key:'{my-api-key}'

I want to write this endpoint in Refit interface in another app that will send files to this endpoint along with other form data.

I'm not sure how this can be be written in Refit. Any help would be appreciated!

Thanks!

@ThaisAbreuCarvalho
Copy link

I had just one file to send but I sent it this way:

[Multipart]
[Post("your route")]
Task Populate([AliasAs("parametername")] byte[] your file);

@xiaolei000129
Copy link

Hi
I also encountered this problem, how do you solve this problem

@xiaolei000129
Copy link

Help the baby. The baby's crying

@azhdarshirinzada
Copy link

Hi I also encountered this problem, how do you solve this problem

send files as byte array or base64 string

@xiaolei000129
Copy link

But it lost its original meaning And then there's no way to get the file information across

@azhdarshirinzada
Copy link

you have a second option to wait when refit devs add this feature. They didn't it for a 2 years FYI))

@xiaolei000129
Copy link

Mm-hmm. Ooooooo the baby is already crying

@xiaolei000129
Copy link

image

I successfully fulfilled the requirement

@TRAD-Anthony-CKO
Copy link

While multipart works, sending form-data in the request is not supported. The content-type is always a JSON internally. Any workaround this?

@Piedone
Copy link

Piedone commented Jul 13, 2024

I'm also struggling with this under OrchardCMS/OrchardCore#16430. I couldn't find a way to send a request with Refit to the below API endpoint:

[HttpPost]
[Route("setup")]
public async Task<ActionResult> Setup(SetupApiViewModel model, IFormFile recipe = null)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants