gpt4 book ai didi

c# - 具有 POST 方法和参数的 BackgroundTransferService

转载 作者:太空狗 更新时间:2023-10-29 21:49:49 25 4
gpt4 key购买 nike

我想上传文件 (VideoFile) 到服务器通过 BackgroundTransferService

我的问题是,我还想与文件(POST 请求)一起发送 2 个参数

那么,在使用 BackgroundTransferService API 时是否可以随文件上传一起发送参数..?

使用 BackgroundTransferService 编写代码:

        BackgroundTransferRequest req = new BackgroundTransferRequest(new Uri("ServerURL", UriKind.Absolute));
req.Method = "POST";
req.TransferPreferences = TransferPreferences.AllowCellularAndBattery;

string uploadLocationPath = "/Shared/Transfers/myVideoFile.mp4";
string downloadLocationPath = "/Shared/Transfers/response.txt";

req.UploadLocation = new Uri(uploadLocationPath, UriKind.Relative);
req.DownloadLocation = new Uri(downloadLocationPath, UriKind.Relative);

req.TransferProgressChanged += req_TransferProgressChanged;
req.TransferStatusChanged += req_TransferStatusChanged;

try
{
BackgroundTransferService.Add(req);
}
catch (Exception ex)
{
MessageBox.Show("Unable to add video to upload queue.\nPlease try again later.", App.appName, MessageBoxButton.OK);
}

请询问是否有人需要更多信息但无法理解我的问题。

我想要快速回复。是或否.. 如果是,那么如何..?

最佳答案

几周前我遇到了类似的问题。我以某种方式通过 HttpClient 管理了这个文件上传。

检查代码

        HttpClient client = new HttpClient();
StorageFile file = null; // assign your file here

MultipartFormDataContent formdata = new MultipartFormDataContent();
formdata.Add(new StringContent("value"), "key");
formdata.Add(new StreamContent(await file.OpenStreamForReadAsync()), "file", "recordedVideoFile2.mp4");

var response = await client.PostAsync(new Uri("URL here"), formdata);

关于c# - 具有 POST 方法和参数的 BackgroundTransferService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30048147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com