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

时间:2018-12-10 11:37:14

标签: c# forms xamarin server

我想使用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
    }

0 个答案:

没有答案