You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
Mohamed Aslam
18 days agoNew member | Level 2
file upload failed randomly
While uploading the document using the Dropbox API [https://content.dropboxapi.com/2/files/upload],
randomly the document gets not uploaded, the file presents with 0 bytes, if i open below,
".pdf files are supported but something went wrong/ dropbox"
Why? It occurs randomly, could you please check this from your end?
Note: I'm using the Dropbox in Web - Windows (Basic plan)
- Greg-DBDropbox Staff
The /2/files/upload Dropbox API endpoint is a "content-upload" style endpoint, so the client needs to send the file data it wants to upload in the request body. If a /2/files/upload call results in a file with a size of 0 bytes, that should mean that the request body sent to /2/files/upload was empty.
I'm not aware of any current issues on our side that would unexpectedly result in 0 byte files, so you should check if/why your network client is sending an empty request body in those cases. For example, check that your code has access to the expected file data it intended to put into the request body, etc and is successfully setting it. You may want to check the documentation for your platform/network client to see if you can enable some verbose logging, or use a debugger to troubleshoot in more detail.
- Mohamed AslamNew member | Level 2
Hi Greg,
Thanks for your update.I already pointed out that the issue was reproduced occasionally for me, and i dont know the exact reason of it.
Further, one of the user in our organization faced this issue frequently.
Please find the below code, that we have used to upload document to Dropbox:// Create the file metadata var fileMetadata = new { autorename = true, mode = "add", mute = false, path = $"{pathDisplay}/{fileName}.pdf", }; // Define the API endpoint and request headers string url = "https://content.dropboxapi.com/2/files/upload"; var requestObj = new HttpRequestMessage(HttpMethod.Post, url); requestObj.Headers.Authorization = new AuthenticationHeaderValue(Bearer, accessToken); requestObj.Headers.Add("Dropbox-API-Arg", JsonConvert.SerializeObject(fileMetadata)); // Use the provided fileStream if it is not null, otherwise use fileContent if (fileStream != null) { requestObj.Content = new StreamContent(fileStream); } else { requestObj.Content = new ByteArrayContent(fileContent); } requestObj.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); // Send the request and get the response var responseObj = await this.httpClient.SendAsync(requestObj).ConfigureAwait(false);
We have passing Stream and ByteArray Content like below,// Use the provided fileStream if it is not null, otherwise use fileContent if (fileStream != null) { requestObj.Content = new StreamContent(fileStream); } else { requestObj.Content = new ByteArrayContent(fileContent); }
There is no issue while uploading the document using ByteArrayContent, they only issue occurs occasionally was using the StreamContent.
In our organization, we have been using Google drive, and OneDrive too, they are working fine without any issue. Same kind of parameters and request are send for all drives.- Greg-DBDropbox Staff
Thanks for following up. It sounds like the issue is sometimes occurring when you use 'new StreamContent(fileStream)', but it's not clear from just this code what the issue may be, so I recommend troubleshooting that particular code path. For instance, you may want to reproduce the issue and inspect what is happening when the issues occurs; you can use a debugger to inspect the state of your code and see if/when and why that data may not be getting populated.
If you've inspected this though and are sure the data is always getting populated in the request body when you see a 0 byte file result, please share some verbose network logging showing that so we can look into it. Thanks!
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,915 PostsLatest Activity: 24 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!