通过Xamarin将视频上传到Azure存储

时间:2017-12-29 12:10:21

标签: c# azure xamarin video xamarin.forms

我正在尝试将视频文件上传到我的Azure存储帐户。我已经让它处理图像,但是尝试查看上传的视频会显示消息"不支持视频格式或MIME类型"。视频格式为mp4。

我使用以下代码上传:

public async Task UploadVideo(Stream video, string path)
{

    var container = GetContainer("videos");

    // Creates the container if it does not exist
    await CreateContainer(container);

    //Gets the file extension
    string lastPart = path.Split('.').Last();

    // Uploads the video to the blob storage
    CloudBlockBlob videoBlob = container.GetBlockBlobReference(path);
    videoBlob.Properties.ContentType = "video/" + lastPart;
    await videoBlob.UploadFromStreamAsync(video);
} 

我做错了吗?

由于

编辑:

这是我用来在手机上捕捉视频的代码:

    private async Task TakeVideoButton_Clicked(object sender, EventArgs e)
    {
        if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakeVideoSupported)
        {
            await DisplayAlert("No Camera", ":( No camera avaialble.", "OK");
            return;
        }

        mediaFile = await CrossMedia.Current.TakeVideoAsync(new Plugin.Media.Abstractions.StoreVideoOptions
        {
            Name = "video.mp4",
            Directory = "DefaultVideos",
        });

        if (mediaFile == null)
            return;

        await DisplayAlert("Video Recorded", "Location: " + mediaFile.Path, "OK");
        videoStream = mediaFile.GetStream();

        file.Dispose();
    }

1 个答案:

答案 0 :(得分:1)

我刚刚在手机上测试了这个而不是我的模拟器,它在那里工作得很好,所以我假设它纯粹是模拟器相关的问题。