How to upload files using NET CORE and Refit

旧巷老猫 提交于 2020-06-16 16:54:46

问题


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

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


回答1:


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);


来源:https://stackoverflow.com/questions/48253505/how-to-upload-files-using-net-core-and-refit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!