UpoadOperationProgress is returning bytessent = bytestosend instantly

66 views Asked by At

After I got my uploadoperation to complete successfully, I am now trying to get some progress UI. right now here's my code including the progress callback and the handler for that callback.

public async Task<UploadOperation> BackgroundUploadVideoAsync(IStorageFile file, string gfyName)
{
    BackgroundUploader uploader = new BackgroundUploader();

    //… Create upload ...


    var partOperation = await uploader.CreateUploadAsync(new Uri("https://filedrop.gfycat.com/"), contentParts, "form-data", Guid.NewGuid().ToString() );
    var progress = new Progress<UploadOperation>(Shell.Current.HandleUpload);
    try
    {
        await partOperation.StartAsync().AsTask(progress);
        return partOperation;
        //var response = await operation.StartAsync().AsTask();
    }
    catch(Exception e)
    {

        var status = BackgroundTransferError.GetStatus(e.HResult);
        //await new MessageDialog($"An error occurred: {status}").ShowAsync();

    }
    return partOperation;
}

public async void HandleUpload(UploadOperation operation)
{
    await Dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
    {
        var percent = operation.Progress.BytesSent / operation.Progress.TotalBytesToSend;
        progressBar.Value = Math.Truncate((double)percent);
        });
    }
}

The problem is when HandleUpload gets called, the 'bytessent' and 'bytestosend' are equal immediately, and my progress bar is set to 100% and waits there until the task is complete. I've never dealt with progress callbacks before so I might be doing it completely wrong.

0

There are 0 answers