question

Joe-0222 avatar image
0 Votes"
Joe-0222 asked JarvanZhang-MSFT answered

Xamarin: How to upload files from device?

I am trying to add functionality to my Android and iOS app that would allow a user to upload a file. I have seen lots of plugins to do it but they all seem to be only for images and videos. I would need a way for a user to upload .gat and .kar files. Does anyone know if there is a way to do this? Any help would be appreciated.

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JarvanZhang-MSFT avatar image
1 Vote"
JarvanZhang-MSFT answered

Hello,​

Welcome to our Microsoft Q&A platform!

How to upload files from device

Try to use Xamarin.Essentials.FilePicker api to pick the file, you could set the file type to all(*) for upload any file.

private async void Button_Clicked(object sender, EventArgs e)
{
    var customFileType =
        new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable<string>>
        {
            { DevicePlatform.iOS, new[] { "public.my.comic.extension" } }, // or general UTType values
            { DevicePlatform.Android, new[] { "*/*" } },
        });
    var options = new PickOptions
    {
        PickerTitle = "Please select a comic file",
        FileTypes = customFileType,
    };
    var result = await FilePicker.PickAsync(options);
}

Check the doc: https://docs.microsoft.com/en-us/xamarin/essentials/file-picker?tabs=android

Best Regards,

Jarvan Zhang



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.