使用Xamarin Forms中的CrossMedia插件将图像上传到服务器

loading...


0

我想使用Xamarin表单中的CrossMedia插件将图像上传到服务器 . 我从galary获取图像但无法将其上传到服务器 .

这是我做过的代码:

private async void profileUploadTap_Tapped(object sender, EventArgs e)
    {
        await CrossMedia.Current.Initialize();
        if (!CrossMedia.Current.IsPickPhotoSupported)
        {
            await DisplayAlert("Error", "This is not supported on your device", "Ok");
            return;
        }

        var mediaOptions = new PickMediaOptions()
        {
            PhotoSize = PhotoSize.Medium
        };
        var selectedImageFile = await CrossMedia.Current.PickPhotoAsync(mediaOptions);

        if (selectedImageFile == null)
        {
            await DisplayAlert("Error", "There was an error when trying to get your image, please try again", "Ok");
            return;
        }

        profileImage.Source = ImageSource.FromStream(() => selectedImageFile.GetStream());
        UploadToServer(selectedImageFile.GetStream());
    }


    public void UploadToServer(Stream stream)
    {
        // here are i want to upload to server
    }

loading...

0回答

No Data

评论

暂时没有评论!