Windows Phone 8.1使用HTTP多部分表单数据将视频上载到远程服务器

时间:2015-01-27 12:39:28

标签: c# windows-phone-8 windows-phone-8.1

我在某个当前项目中遇到了麻烦,觉得我现在被卡住了。我尝试使用HTTP帖子和多部分表单数据进行视频上传。 我想用json文件在服务器上上传视频文件。我在服务器上创建了一个json文件和json文件成功上传,但后来我在多部分请求中添加了视频文件,这两个文件都没有在服务器上传。我试图在谷歌上找到一些代码,但没有成功。请帮帮我

视频选择从视频中心成功(视频选择代码): -

private void btnUpload_Click(object sender, RoutedEventArgs e)
{

    try
    {
        FileOpenPicker openPicker = new FileOpenPicker();
        openPicker.ViewMode = PickerViewMode.Thumbnail;
        openPicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
        openPicker.ContinuationData["Operation"] = "UpdateVideo";//"UpdateProfilePicture";
        openPicker.FileTypeFilter.Add(".3GP");
        openPicker.FileTypeFilter.Add(".MP4");
        openPicker.FileTypeFilter.Add(".WMV");
        openPicker.FileTypeFilter.Add(".AVI");
        openPicker.FileTypeFilter.Add(".MOV");
        openPicker.FileTypeFilter.Add(".3G2");
        openPicker.PickSingleFileAndContinue();
        view.Activated += view_Activated;

    }
    catch { }
}

public void view_Activated(CoreApplicationView sender, Windows.ApplicationModel.Activation.IActivatedEventArgs args1)
{
    FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs;
    if (args != null)
    {
        if (args.Files.Count == 0) return;
        view.Activated -= view_Activated;
        VideoStorageFile = args.Files[0];
    }
}

视频上传代码: -

public async void UploadVideo()
{
    try
    {
        videoUid = Guid.NewGuid().ToString();
        getVideoJson();
        HttpClient httpClient = new HttpClient();
        HttpMultipartFormDataContent entity = new HttpMultipartFormDataContent();
        IInputStream inputStream = await VideoFileJson.OpenAsync(FileAccessMode.Read);
       IInputStream videoInputStream = await VideoStorageFile.OpenAsync(FileAccessMode.Read);
        entity.Add(new HttpStreamContent(inputStream), VIDEO_FILE_NAME, VideoFileJson.Name);
        entity.Add(new HttpStreamContent(videoInputStream), "videoFile", VideoStorageFile.Name);
        entity.Add(new HttpStringContent(videoUid), name: "videoUid");
        HttpResponseMessage response = await httpClient.PostAsync(new Uri("Url"), entity);
        String receiveStream = response.Content.ReadAsStringAsync().ToString();
        txtVideoDes.Text = receiveStream;
        MessageBox.Show("Successfull Submit");
    }
    catch(Exception ex) {
        MessageBox.Show(ex.Message);
    }

}

0 个答案:

没有答案