简体   繁体   English

如何在xamarin表单中实现多文件上传?

[英]How to achieve multiple file upload in xamarin forms?

I am working on xamarin forms, where I am trying to achieve multiple file upload.我正在处理 xamarin 表单,我正在尝试实现多个文件上传。 What I have tried is using file picker plugin which will give me upload one file but my requirement is multiple file upload.我尝试过的是使用文件选择器插件,它可以让我上传一个文件,但我的要求是上传多个文件。

//My xaml
<Button Text="Pick File" Clicked="Button_Clicked" HorizontalOptions="Center"  
               VerticalOptions="Center"/>
//my C#
var file = await CrossFilePicker.Current.PickFile();

//MY API (WEB API DOT NET CORE) //我的API(WEB API DOT NET CORE)

public async Task<IActionResult> RaiseTicket()
{
    //I am sending few object in header those things I am reading here
    var mslAddProviderUser = JsonConvert.DeserializeObject<MRaiseTicket>(Request.Headers["mdl"]);

    var boundary = MultipartRequestHelper.GetBoundary(MediaTypeHeaderValue.Parse(Request.ContentType), _defaultFormOptions.MultipartBoundaryLengthLimit);
    var reader = new MultipartReader(boundary, HttpContext.Request.Body);
    //This section variable holds my all files and It is working I have tested using our web application
    **var section = await reader.ReadNextSectionAsync();** 
}

How to do for multiple files and is there another way to achieve the same?如何处理多个文件,还有其他方法可以实现吗?

Xamarin doesn't implement any cross platform way to pick files, so you either need to implement it yourself using the platform APIs or to find the plugin that does that. Xamarin 没有实现任何跨平台方式来选择文件,因此您需要使用平台 API 自己实现它,或者找到执行此操作的插件。 As the plugin to pick multiple files doesn't seem to exist, then you need to implement it yourself using native APIs and dependency injection.由于选择多个文件的插件似乎不存在,因此您需要使用本机 API 和依赖项注入自己实现它。 For example, this is API for iOS: https://developer.apple.com/documentation/uikit/uidocumentpickerviewcontroller?language=objc , you need to implement file picker for iOS using this API and then use it from Xamarin using dependency injection (or shared project but it is rarely used today though it is simpler).例如,这是 iOS 的 API: https : //developer.apple.com/documentation/uikit/uidocumentpickerviewcontroller? language =objc ,您需要使用此 API 为 iOS 实现文件选择器,然后使用依赖注入从 Xamarin 中使用它(或共享项目,但今天很少使用,尽管它更简单)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM