Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
I have tried with downloading and uploading functions, it gives the progress data alright, but I can not set that data to progress bar. I have worked with couple of hours but can not place that process status in the progress bar or any other way. I have attached codes of Upload
private async Task ChunkUpload()
{
string path = UploadFolder + "/" + UploadFile;
FileStream stream = UploadFileStream;
int chunkSize = 128 * 1024;
DropboxClient dbx = new DropboxClient(SystemVariables.WebAcccessToken);
int numChunks = (int)Math.Ceiling((double)stream.Length / chunkSize);
byte[] buffer = new byte[chunkSize];
string sessionId = null;
for (var idx = 0; idx < numChunks; idx++)
{
var byteRead = stream.Read(buffer, 0, chunkSize);
using (var memSream = new MemoryStream(buffer, 0, byteRead))
{
if (idx == 0)
{
var result = await dbx.Files.UploadSessionStartAsync(false, memSream);
sessionId = result.SessionId;
}
else
{
var cursor = new UploadSessionCursor(sessionId, (ulong)(chunkSize * idx));
var percentage = 100 * ((chunkSize * idx) / (double)stream.Length);
pValue = (int)Math.Ceiling((decimal)percentage);
// Approach 1
var progressIndicator = new Progress<int>(ReportProgress);
int uploads = await UploadProgress(progressIndicator);
// Approach 2
/*
Thread t = new Thread(new ThreadStart(this.DoProcess));
t.Start();
while (t.IsAlive) // while thread is running
{
Application.DoEvents(); // Allow UI to refresh if needed
Thread.Sleep(10000); // sleep a while to avoid processor load
t.Abort();
}*/
if (idx == numChunks - 1)
{
await dbx.Files.UploadSessionFinishAsync(cursor, new CommitInfo(path), memSream);
}
else
{
await dbx.Files.UploadSessionAppendV2Async(cursor,false, memSream);
}
}
}
}
}
public delegate void UpdateProgressBarDelegate(int progress);
public UpdateProgressBarDelegate UpdateProgressBar;
private void UpdateProgressBarMethod(int progress)
{
IAsyncResult result = this.progressBar1.BeginInvoke(
(MethodInvoker)delegate()
{
progressBar1.Value = progress;
Text = progress.ToString();
//txtLogDetails.Text = message;
});
}
private void DoProcess()
{
UpdateProgressBarMethod(pValue);
}
void ReportProgress(int value)
{
progressBar1.Value = value;
}
async Task<int> UploadProgress(IProgress<int> progress)
{
int processCount = await Task.Run<int>(() =>
{
if (progress != null)
{
progress.Report(pValue);
}
return pValue;
});
return processCount;
}
You can see the 2 approaches that I have tried to update progress bar value,
but can not see the update in progress bar.
It will be great if you provide the detail code for display updates in progress bar from the scrat
This looks like a continuation of your question from your other thread. As I mentioned there, this part isn't about Dropbox, so I can't offer any help. Also, this probably isn't the best forum for getting help for questions like this. You may want to try StackOverflow, or a forum for .NET.
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!