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 f...
Mohamed Aslam
New 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-DB
17 days agoDropbox 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!
- Mohamed Aslam16 days agoNew member | Level 2
Hi Greg,
We tried reproduce this issue locally, but it can't reproduced. It was reproduced occasionally for us,
And further, we have attached the issue screenshot(Previously reproduced one),
Please check the issue from your end, with the attached screenshot.
Thanks,
Mohamed Aslam- Greg-DB16 days agoDropbox Staff
That error in your screenshot would occur when attempting to view a .pdf file with a size of 0 bytes, since there's no file content to view. That being the case, you'll need to investigate why the file was uploaded without content.
I tested this out myself and haven't been able to reproduce an issue of unexpected 0 byte file uploads, and I don't see other reports of any issues like this, so it sounds like it's specific to your particular environment/scenario. That being the case, you'll need to troubleshoot the uploads locally.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,915 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!