Dropbox API upload sessions v2 using PHP (bug fixing and workflow suggestion) #11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thanks for this library. I'm using this in a project where it uploads several large files to Dropbox using API. I'm using this upload sessions and tracking the percent progress of uploads via chunk(offset size) / total size. This computation is done outside of your library (in my app)
While working with your library, I came across several bugs that made it impossible to start, append and finish the upload sessions. Also the entry class is misplaced so I fix some of it.
In your upload session methods, it assumes a file path is provided and read it via
file_get_contents. This almost difficult for me to work since it assumes the file is already broken down into. This will also have memory issues (if it tries to read large chunks or even the whole file.My approach is simple. This is how I'm using your library in my app right now for upload sessions. I simply read the large file to upload on a chunk by chunk basis using generator like this:
Where the
$handleis the output of fopen for the large file and$chunk_sizeis the size of the chunk in bytes. This is opened like this (where $path is the path to the large file to be uploaded):Then I do a
foreachloop for each chunk and call to your Dropbox upload session library methods passing each chunk instance. E.g. like this: (this is not complete code but at least you will get an idea as to how it is being used)I tested this thoroughly in my app and now works good for very large files (example uploading > 200MB in slow connection will still work). Feel free to review and merge this to your library if you think its useful.
For now I'm pointing my own forked version to my app composer.json.