Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
Rephoto
3 years agoHelpful | Level 5
Error while copying content to a stream in C#
Hi, I encountered the problem "Error while copying content to a stream" when executing the above code. Is there any way to fix it? try { var chunkSize = 16 * 1024 * 1024; ...
- 3 years ago
Rephoto If you wish to optimize your upload process, please refer to the Performance Guide: https://developers.dropbox.com/dbx-performance-guide
That offers some ways you may be able to improve your effective overall upload speed. For example, there are batching and parallelization features you can use.
For instance, as Здравко noted, the default upload session type is "sequential", but you can use "concurrent" to upload file pieces in parallel. That would require you to make some more changes to your code to properly send those pieces in parallel though.
Rephoto
3 years agoHelpful | Level 5
I changed the code and there weren't any errors but the Entries returned all had a status of fales.
Can you tell me where I'm going wrong?
Thanks
Здравко
3 years agoLegendary | Level 20
Rephoto, What are you doing? Batch is used when you want to upload multiple files at once, not to split one file upload and do pieces upload simultaneous!!! Use concurrent upload session to do that.
- Rephoto3 years agoHelpful | Level 5
Oh sorry,
I will investigate further :(( - Здравко3 years agoLegendary | Level 20
Rephoto wrote:ЗдравкоHi, I tried again with the code below to upload small files (e.g. 10, 20MB). But the result just failed. :))
...
Hm..🤔 Probably I miss something, but where in your code you did upload files actually? 🧐 I cannot figure out where is this place/codeline. Please point out where you pass your files content to. Also don't forget that you should close every single session before finishing - so to be ready for finish! 😉
Add: When you have some error, don't forget to post the actual error/unexpected result content too. There is valuable information describing the error.
- Здравко3 years agoLegendary | Level 20
Rephoto wrote:Здравко
Oh, So I'm missing the file upload part. But I don't know which one to use?In general, you should use UploadSessionAppendV2Async method to upload stream' data. In such case you can combine the batch with big files upload either sequential or concurrent. When you know that only small files are going to upload, using single call of UploadSessionStartAsync to prepare a session (together with data upload and close) may be more suitable (instead of using UploadSessionStartBatchAsync - neither data can be uploaded nor closing it).
Let's hope this clarifies matter.
- Здравко3 years agoLegendary | Level 20
Rephoto, Why are you trying to upload the same stream twice? 🤔 Previously you skipped upload at all, now just opposite! 🙂
Something else: Why you skipped finishing the all sessions in batch? In such a way, there is no optimization! Even more - you can do the same with a single call. 😉
- Здравко3 years agoLegendary | Level 20
If you want to just upload a single small file and that's all, using UploadAsync is the bast. In such a way you create session, upload and close the content and finish the upload - all in this single call. Here is no any optimization. In your last code snippet you make it rather slower - 2 calls instead of one.
If you want to make multiple files upload at once and optimize the process of finish, you can use UploadSessionFinishBatchAsync as you have it done already (or rather tried to use).
That's it. Clarify to yourself what actually you want to do.
- Rephoto3 years agoHelpful | Level 5
I have a large number of photos (including about 100 photos under 10Mb). If I use UploadAsync it is getting a lot of too_many_write_operations/ errors.
And that's why I need a new solution to push these photos to Dropbox in a short time. To perform the next tasks - Здравко3 years agoLegendary | Level 20
Create and upload sessions (and close it) for all files that are less than 150MB in parallel and finally finish all them in a single call. 'too_many_write_operations' is sensitive to number of finishes. When you have many finishes it becomes likely to appears such a error. When you combine them in single call they become less likely.
- Rephoto3 years agoHelpful | Level 5
So the best way for me to do this task is:
Use UploadSessionStartBatchArg to create sessions, followed by using UploadSessionAppendV2Async to upload each file. And finally, use UploadSessionFinishBatchAsync to complete the task, right?
Thanks - Здравко3 years agoLegendary | Level 20
Hm... Ok right.
- Rephoto3 years agoHelpful | Level 5
I have tried this before. But they all got this error 😅
- Здравко3 years agoLegendary | Level 20
You should debug yourself connection breaks, but there are other... let say strange things in your code. You're starting upload file content at expected file end instead of the beginning. Why? By the way this is error since the file content cannot have "gaps". Even without connection break, you would receive error denoting inconsistent files.
- Здравко3 years agoLegendary | Level 20
Do you understand that on that place has to be the offset in the file in Dropbox session where ongoing upload would go to? In this context, what would be between offset 0 up to memStream.Length? 🤔 According your code, there is nothing. 😜
Read the documentation with a bit more care!
- Rephoto3 years agoHelpful | Level 5
Yes 😅,
I have done uploading small sized files. And I continue to upload files larger than 150MB in size. But when I use "var result = await _client.Files.UploadSessionStartAsync(body: memStream, sessionType: UploadSessionType.Concurrent.Instance);" I encountered this error ""Error while copying content to a stream."" - Здравко3 years agoLegendary | Level 20
Rephoto wrote:...
I have done uploading small sized files. And I continue to upload files larger than 150MB in size. ...The only difference when you upload larger files, compared to small files, is that you will need to slice file to pieces and upload every piece to its corresponding place in the file session (not on just some place - as you have tried already for small files). If you will left gap in file... it's error (again), doesn't matter file size!
One more thing you should keep in mind when select files pieces size when concurrent upload is selected - every piece must be uploaded to place which offset is an exact power of 2!!! Violating this rule is error! In general the pieces can be different sized while following previous rule, but an easy way to cover the requirement is to select the same size for all pieces (possibly except the last piece - its size is whatever has been left); a size that is exact power of 2 and not less than 4MB (4*1024*1024).
When some error brings up, post the exact code and point out the exact position.
I will avoid giving language/platform related advises - you should be able debug such errors alone. It's not something Dropbox API related.
- Greg-DB3 years ago
Dropbox Community Moderator
Rephoto It's not entirely clear what that latest issue is, but as Здравко said, it doesn't appear to be from the Dropbox API itself; you'll need to debug this more in your code. Also, it looks like the error message is cut off in your screenshot, so make sure you're reading the whole error message when doing so.
About Discuss Dropbox Developer & API
Make connections with other developers
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If 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, Facebook or Instagram.
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!