The Community is undergoing a major upgrade. Find out more, ask us questions or share your thoughts here.
Forum Discussion
RealProgrammer
4 years agoExplorer | Level 4
System.ArgumentNullException: when inititating concurrent upload
Hi, I've been working on a project and the requirement is to upload files to Dropbox concurrently and in chunks. So, I wrote the following code to accomplish the task.
I initiated the request using the following code.
public async Task<string> InitiateChunkUploadAsync(ProcessFileViewModel fileModel, CancellationToken cancellationToken) { try { _logger.LogInformation($"Initiating multi part upload to Dropbox."); var uploadSessionStartResult = await _client.Files.UploadSessionStartAsync(sessionType: UploadSessionType.Concurrent.Instance); return uploadSessionStartResult.SessionId; } catch (DropboxException ex) { _logger.LogError(ex, $"An error occurred while initiating multi part upload to Dropbox."); } catch (Exception ex) { _logger.LogError(ex, $"An error occurred while initiating multi part upload to Dropbox."); } }
and I'm getting the following error
System.ArgumentNullException: Value cannot be null. (Parameter 'body') at MultiPartChunkUpload.Web.Services.Storage.DropboxUploadService.InitiateChunkUploadAsync(ProcessFileViewModel fileModel, CancellationToken cancellationToken) in ... at MultiPartChunkUpload.Web.Controllers.FileController.SaveChunkOnDropBoxAsync(IFormFileCollection files, ChunkMetaData chunkMetaData, ChunkUploadFileResult chunkUploadFileResult, CancellationToken cancellationToken) in ... at MultiPartChunkUpload.Web.Controllers.FileController.SaveToCloud(CloudProvider cloudProvider, IFormFileCollection files, ChunkMetaData chunkMetaData, CancellationToken cancellationToken) ... at MultiPartChunkUpload.Web.Controllers.FileController.ChunkSave(IFormFileCollection files, String metaData, CancellationToken cancellationToken) in ...
When I tried to add body in the UploadSessionStartAsync, as below
var uploadSessionStartResult = await _client.Files.UploadSessionStartAsync(sessionType: UploadSessionType.Concurrent.Instance, body: fileModel.Stream);
I got another error, which is expecting
Dropbox.Api.ApiException`1[Dropbox.Api.Files.UploadSessionStartError]: concurrent_session_data_not_allowed/ at MultiPartChunkUpload.Web.Services.Storage.DropboxUploadService.InitiateChunkUploadAsync(ProcessFileViewModel fileModel, CancellationToken cancellationToken) in ... at MultiPartChunkUpload.Web.Controllers.FileController.SaveChunkOnDropBoxAsync(IFormFileCollection files, ChunkMetaData chunkMetaData, ChunkUploadFileResult chunkUploadFileResult, CancellationToken cancellationToken) in ... at MultiPartChunkUpload.Web.Controllers.FileController.SaveToCloud(CloudProvider cloudProvider, IFormFileCollection files, ChunkMetaData chunkMetaData, CancellationToken cancellationToken) in ... at MultiPartChunkUpload.Web.Controllers.FileController.ChunkSave(IFormFileCollection files, String metaData, CancellationToken cancellationToken) in ...; Request Id: 71753a2c841a4de284321c8aab374bdf
I've looked at the source code and found this line problematic. Looks like chunk concurrent operation is not yet implemented in .NET SDK.
Can someone please guide me if there is an error with my code or I figured it out correctly that this is not implemented? If not implemented yet, any workaround or when we expect this to be implemented?
Thanks in advance.
Apologies for the confusion. You can start a concurrent upload session in the .NET SDK by passing an empty body, like this:
var uploadSessionStartResult = await _client.Files.UploadSessionStartAsync(sessionType: UploadSessionType.Concurrent.Instance, body: new MemoryStream());
I'll ask the team to see if we can update the SDK to make this easier/more obvious in the future.
- Greg-DBDropbox Staff
Apologies for the confusion. You can start a concurrent upload session in the .NET SDK by passing an empty body, like this:
var uploadSessionStartResult = await _client.Files.UploadSessionStartAsync(sessionType: UploadSessionType.Concurrent.Instance, body: new MemoryStream());
I'll ask the team to see if we can update the SDK to make this easier/more obvious in the future.
- RealProgrammerExplorer | Level 4
Thanks for the help. Your answer did the trick.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,875 PostsLatest Activity: 2 hours agoIf you need more help you can view your support options (expected response time for an email or 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!