refit icon indicating copy to clipboard operation
refit copied to clipboard

Question: Multipart form-data with Refit

Open johnybaryah opened this issue 5 years ago • 10 comments

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='[email protected]' '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!

johnybaryah avatar May 23 '20 20:05 johnybaryah

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

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

ThaisAbreuCarvalho avatar Sep 30 '22 16:09 ThaisAbreuCarvalho

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

xiaolei000129 avatar Oct 31 '22 03:10 xiaolei000129

Help the baby. The baby's crying

xiaolei000129 avatar Oct 31 '22 03:10 xiaolei000129

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

send files as byte array or base64 string

mrn06ody avatar Oct 31 '22 07:10 mrn06ody

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

xiaolei000129 avatar Oct 31 '22 07:10 xiaolei000129

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

mrn06ody avatar Oct 31 '22 07:10 mrn06ody

Mm-hmm. Ooooooo the baby is already crying

xiaolei000129 avatar Oct 31 '22 07:10 xiaolei000129

image

I successfully fulfilled the requirement

xiaolei000129 avatar Nov 01 '22 02:11 xiaolei000129

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

TRAD-Anthony-CKO avatar Jun 25 '24 14:06 TRAD-Anthony-CKO

I'm also struggling with this under https://github.com/OrchardCMS/OrchardCore/issues/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)

Piedone avatar Jul 13 '24 18:07 Piedone