-
Notifications
You must be signed in to change notification settings - Fork 2.3k
enh(chunk): Add docs for chunked upload v2 #10740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,13 +10,113 @@ Uploading large files is always a bit problematic as your connection can be inte | |
| which will fail your entire upload. Nextcloud has a chunking API where you can | ||
| upload smaller chunks which will be assembled on the server once they are all uploaded. | ||
|
|
||
| Usage | ||
| ----- | ||
| There are two versions of the chunking API. Version 1 is the original version and version 2 was built as a backward compatible extension to support uploads directly to supporting target storages like S3. Version 2 is the recommended version to use. | ||
|
|
||
| Version 2 comes with a few additional requirements and limitations to consider (compared to version 1): | ||
|
|
||
| - Every request needs to have a ``Destination`` header present which specifies the target path of the file | ||
| - The naming of the individual chunks is limited to be a number between 1 and 10000 | ||
| - The chunks will be assembled in the order of their names | ||
| - The size of chunks must be between 5MB and 5GB (except for the last chunk, which can be smaller) | ||
| - Chunks cannot be downloaded from the upload directory | ||
|
|
||
| Nextcloud will expire the upload directory after 24 hours of inactivity. This means that if you start an upload and do not finish it within 24 hours, the upload directory will be deleted and the upload will fail. | ||
|
|
||
| Chunked upload v2 | ||
| ----------------- | ||
|
|
||
| The API is only available for registered users of your instance. And uses the path: | ||
| ``<server>/remote.php/dav/uploads/<userid>``. For this guide we will assume: | ||
| ``https://server/remote.php/dav/uploads/roeland`` | ||
|
|
||
|
|
||
|
|
||
| Starting a chunked upload | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| A chunked upload is handled in 1 folder. This is the location all the chunks | ||
| are uploaded to. | ||
|
|
||
| Start by creating a folder with a unique name. You can list the current available | ||
| folder but if you take a random UUID chances of collision are tiny. | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| curl -X MKCOL -u roeland:pass \ | ||
| https://server/remote.php/dav/uploads/roeland/myapp-e1663913-4423-4efe-a9cd-26e7beeca3c0 \ | ||
| --header 'Destination: Destination https://server/remote.php/dav/files/roeland/dest/file.zip' | ||
|
|
||
| Uploading chunks | ||
| ^^^^^^^^^^^^^^^^ | ||
|
|
||
| Once a folder for the chunks has been created we can start uploading the chunks. | ||
|
|
||
| - The naming of the individual chunks is limited to be a number between 1 and 10000 | ||
| - The chunks will be assembled in the order of their names | ||
| - The size of chunks must be between 5MB and 5GB (except for the last chunk, which can be smaller) | ||
|
|
||
|
|
||
| .. code-block:: console | ||
|
|
||
| curl -X PUT -u roeland:pass \ | ||
| https://server/remote.php/dav/uploads/roeland/myapp-e1663913-4423-4efe-a9cd-26e7beeca3c0/00001 \ | ||
| --data-binary @chunk1 \ | ||
| --header 'Destination: Destination https://server/remote.php/dav/files/roeland/dest/file.zip' | ||
|
|
||
| curl -X PUT -u roeland:pass \ | ||
| https://server/remote.php/dav/uploads/roeland/myapp-e1663913-4423-4efe-a9cd-26e7beeca3c0/00002 \ | ||
| --data-binary @chunk2 \ | ||
| --header 'Destination: Destination https://server/remote.php/dav/files/roeland/dest/file.zip' | ||
|
|
||
| This will upload 2 chunks of a file. The first chunk is 10MB in size and the second | ||
| chunk is 5MB in size. | ||
|
|
||
| Assembling the chunks | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| Assembling the chunk on the server is a matter of initiating a move from the client. | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| curl -X MOVE -u roeland:pass | ||
| --header 'Destination:https://server/remote.php/dav/files/roeland/dest/file.zip' \ | ||
| https://server/remote.php/dav/uploads/roeland/myapp-e1663913-4423-4efe-a9cd-26e7beeca3c0/.file | ||
|
|
||
| The server will now assemble the chunks and move the final file to the folder ``dest/file.zip``. | ||
|
|
||
| If a modification time should be set, you can by adding it as header with date as unixtime: | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| curl -X MOVE -u roeland:pass | ||
| --header 'Destination: https://server/remote.php/dav/files/roeland/dest/file.zip' \ | ||
| --header 'X-OC-Mtime: 1547545326' \ | ||
| --header 'Destination: https://server/remote.php/dav/files/roeland/dest/file.zip' \ | ||
| --header 'X-OC-Mtime: 1547545326' \ | ||
| Otherwise the current upload date will be used as modification date. | ||
|
|
||
| The chunks and the upload folder will be deleted afterwards. | ||
|
|
||
| Aborting the upload | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| If the upload has to be aborted this is a simple matter or deleting the upload folder. | ||
|
|
||
| .. code-block:: | ||
|
|
||
| curl -X DELETE -u roeland:pass \ | ||
| https://server/remote.php/dav/uploads/roeland/myapp-e1663913-4423-4efe-a9cd-26e7beeca3c0/ | ||
|
|
||
|
|
||
| Chunked upload v1 | ||
| ----------------- | ||
|
|
||
| The API is only available for registered users of your instance. And uses the path: | ||
| ``<server>/remote.php/dav/uploads/<userid>``. For this guide we will assume: | ||
| ``https://server/remote.php/dav/uploads/roeland`` | ||
|
|
||
|
|
||
|
|
||
| Starting a chunked upload | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
|
|
@@ -60,7 +160,7 @@ Assembling the chunk on the server is a matter of initiating a move from the cli | |
| The server will now assemble the chunks and move the final file to the folder ``dest/file.zip``. | ||
|
|
||
| If a modification time should be set, you can by adding it as header with date as unixtime: | ||
| ``curl -X MOVE -u roeland:pass --header 'X-OC-Mtime:1547545326' --header 'Destination:https://server/remote.php/dav/files/roeland/dest/file.zip' https://server/remote.php/dav/uploads/roeland/myapp-e1663913-4423-4efe-a9cd-26e7beeca3c0/.file``" | ||
| ``curl -X MOVE -u roeland:pass --header 'X-OC-Mtime:1547545326' --header 'Destination:https://server/remote.php/dav/files/roeland/dest/file.zip' https://server/remote.php/dav/uploads/roeland/myapp-e1663913-4423-4efe-a9cd-26e7beeca3c0/.file``" | ||
| Otherwise the current upload date will be used as modification date. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The upload date is the date of the first/last file uploaded or when the |
||
|
|
||
| The chunks and the upload folder will be deleted afterwards. | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.