5

When I use a POSTMAN to do make a request, my API receives a IList<IFormFile>.

Request using POSTMAN

API

How can I do the same request using Xamarin.Forms with REFIT?

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
Matheus Velloso
  • 175
  • 1
  • 9

1 Answers1

16

You can use IEnumerable<StreamPart> to upload a list of files:

public interface IApi
{
    [Multipart]
    [Post("/api/story/{id}/upload-images")]
    Task UploadImages(int id, [AliasAs("files")] IEnumerable<StreamPart> streams);
}

Then you can call it:

var api = RestService.For<ISomeApi>("http://localhost:61468");
var files = new List<StreamPart>()
{
    new StreamPart(fileStream, "photo.jpg", "image/jpeg"),
    new StreamPart(fileStream2, "photo2.jpg", "image/jpeg")
};

await api.UploadImages(1, files);
Alex Riabov
  • 8,655
  • 5
  • 47
  • 48
  • 2
    if it helps anyone documentation is here: https://github.com/reactiveui/refit#multipart-uploads – D-Go Jul 30 '19 at 15:28