BackgroundTransferService with POST method and parameters

I want to upload a file (VideoFile) to the server via BackgroundTransferService .

My problem is that I also want to send 2 parameters along with the file (POST request).

So, is it possible to send parameters along with file BackgroundTransferService using the BackgroundTransferService API ..?

Code with 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); } 

Please ask if anyone wants more information and cannot understand my question.

I need a quick answer. Yes or No .. and if so, how ..?

+6
source share
2 answers

I encountered a similar problem until a few weeks. I somehow controlled the download of this file using HttpClient .

Check code

  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); 
+2
source

I am not 100% sure what you are trying to do. However, I believe you can through the HTTP headers.

BackgroundTransferRequest.Headers Property
https://msdn.microsoft.com/en-us/library/windows/apps/microsoft.phone.backgroundtransfer.backgroundtransferrequest.headers(v=vs.105).aspx

And as a sender with the Tag property.
https://msdn.microsoft.com/en-us/library/windows/apps/microsoft.phone.backgroundtransfer.backgroundtransferrequest.tag(v=vs.105).aspx

This property can be used to bind user data related to translation. An application can set a value when a transfer request is created. When a transfer request is retrieved using the Request property or the Find (String) method, the Tag property will contain the previously set data. This property is used only by the caller of the application and is ignored by the system. The maximum length of this property is 4000 characters, but it is recommended to keep the data size smaller to improve performance.

+1
source

Source: https://habr.com/ru/post/986554/


All Articles