我想通过BackgroundTransferService
将一个文件(VideoFile)上传到服务器。
我的问题是,我还想在文件上传时发送2个参数(POST请求)。
那么,在使用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);
}
如果有人需要更多信息并且无法理解我的问题,请询问。
我希望能尽快得到回复。是或否,如果是的话,请告诉我如何操作?
BackgroundTransferService
的原因是我还想追踪已上传的字节数和剩余的字节数。只有通过使用BackgroundTransferService
才能跟踪这些统计数据,而不能通过HttpClient
实现。是否有其他替代方案呢? - Keval LangaliaHttpClient
并通过POST请求完成上传(有一些限制)。@FlorianMoser感谢您提供的参考链接。那帮助我解决了我的另一个问题。@learner感谢您提出的替代方案。 - Keval Langalia