I am aware that this question has been submitted multiple times, but the last answers are dated and I wonder whether there would be a solution available today? This is not a feature request. I'm rather looking for any workaround that would work.
I'm using RestSharp on a client which talks with my API. The API replies with an "application/octect-stream" which can take up to several minutes to download. Link to the GitHub code here.
public void Download()
{
if (NewerApp == null) return;
var client = new RestClient(ServerAddress);
var request = new RestRequest("/Apps/", Method.POST);
request.AddParameter("id", CurrentApp.EncryptedId());
request.AddParameter("action", "download");
var asyncHandle = client.ExecuteAsync<App>(request, response => {
HandleResponseToDownloadRequest(response);
});
}
I would need to report the progress of the reception of "response" to my UI to build a progress bar or something like that. I already know the expected amount of data to be received (through a previous API response), I would just need to know how many bytes were received before the full response is received and parsed.
I don't believe RestSharp currently offers a 'report progress' type of event, right? I can see several approaches:
- Use client.DownloadData(request).SaveAs(path);. Maybe the file is created while it is downloaded. I could read the size of the file to report the progress of the download. But my first impression is that the client first downloads the data, then saves the file. In that case, that wouldn't help.
- Using a stream to load the response. Evaluate the size of the stream at regular intervals, or everytime the buffer size extends.
- Change the type of response from the API to another one (send the data in a JSON, for example?).
- Any other option?
What do you think? Anyone has managed to report the progress of the upload?
Can I access the RawBytes of 'response' while ExecuteAsync is still executing? Should I use Execute (without Asyn) instead? Should I use stream and update watch the size of the stream at regular updates?