TUS is a resumable file upload protocol and with MongoDB GridFS, we build an API for uploading files through a REST API and show how to scale this API horizontally using MongoDB as the storage for these files.
Singapore MongoDB User Group March Meetup
16. What is the TUS protocol?
• Simple, open and free
• HTTP-based ( POST, HEAD, PATCH )
• Split file into chunks
• Send smaller pieces, server keeps track of
chunks / offset
• Web and mobile clients library
17. What is the TUS protocol?
POST "/files" HTTP/1.1
Host: tus.example.org
Content-Length: 0
Final-Length: 100
RESPONSE:
HTTP/1.1 201 Created
Location: http://tus.example.org/files/1
18. What is the TUS protocol?
PATCH "/files/1" HTTP/1.1
Host: tus.example.org
Content-Length: 70
Offset: 0
[file data]
RESPONSE:
HTTP/1.1 200 Ok
19. What is the TUS protocol?
HEAD "/files/1" HTTP/1.1
Host: tus.example.org
RESPONSE:
HTTP/1.1 200 Ok
Offset: 70
20. What is the TUS protocol?
PATCH "/files/1" HTTP/1.1
Host: tus.example.org
Content-Length: 30
Offset: 70
[remaining file data]
RESPONSE:
HTTP/1.1 200 Ok
21. Awesome! What about the
servers and the clients?
• tusd - reference server implementation using
Go
• tus-ios-client, native objective-C client library
• tus-jquery, javascript client library
• rubytus, ruby gem
https://github.com/picocandy/rubytus
22. Where are the chunks?
• tusd - reference server implementation using
Go
• tus-ios-client, native objective-C client library
• tus-jquery, javascript client library
• rubytus, ruby gem
https://github.com/picocandy/rubytus
24. What is GridFS?
• GridFS is a specification for storing and retrieving files
that exceed the BSON-document size limit of 16MB.
• Just like the other collections
• By default, GridFS uses two collections with names
prefixed by fs bucket:
• fs.files and fs.chunks
• Use a different bucket name? Yes!
Create multiple buckets in a single database? Oh yes!