Uploads
MASV API clients upload files directly to MASV’s private cloud infrastructure. MASV achieves this by providing pre-signed URLs while abstracting the interaction for each step of the file process.
Packages and authorization
Section titled “Packages and authorization”Files uploaded to MASV belong to a package object — a virtual directory inside of MASV. Each package contains a token that can be used to upload files to that specific virtual directory. A package can be created by interacting with different API endpoints (for example, Portals or Teams).
All requests to upload endpoints require a token passed as an HTTP header, X-Package-Token. This token authorizes the user to add and remove files from the package until the package is finalized.
Lifecycle of an upload
Section titled “Lifecycle of an upload”For each file in the package:
- Add file to the package (API action)
- Create the file in cloud storage
- Collect metadata from cloud storage service
- Identify the number of file chunks
- Obtain authorized URLs to upload each chunk
- Upload all chunks to cloud storage
- Collect metadata for each uploaded chunk
- Once all chunks are uploaded, finalize the file
Then finalize the package.
MASV blueprints
Section titled “MASV blueprints”MASV’s API abstracts interactions with cloud storage services by creating a Blueprint object with four properties:
| Name | Type | Description |
|---|---|---|
url | String | URL that the request should be forwarded to |
method | String | The HTTP method to use (GET, POST, PUT, DELETE) |
headers | JSON | Key-value map of header names and their values |
body | String | HTTP request body |
Chunk size
Section titled “Chunk size”MASV lets you set the chunk size, which divides larger files into segments for transfer. The default chunk size is 100 MiB, but you can adjust the chunk_size parameter to optimize for speed or reliability.
Storage services like Amazon S3 limit the number and size range for chunks. MASV uses the endpoint https://api.massive.app/v1/system/packages/spec to pass chunk parameters:
| Parameter | Description |
|---|---|
max_chunk_count | Maximum number of chunks permitted (10,000 for S3) |
max_chunk_size | Maximum chunk size in bytes (5 GiB for S3) |
min_chunk_size | Minimum chunk size in bytes (5 MiB for S3) |
Upload API interaction
Section titled “Upload API interaction”Each package belongs to either a Team or Portal on MASV. To create a package for a Team, you must provide an API key. To create a package for a Portal, you do not need an API key (but must provide an access code if the Portal requires it).
1) Create a package
Section titled “1) Create a package”A. Team package
Section titled “A. Team package”| Method | Route |
|---|---|
POST | /teams/{team_id}/packages |
Headers
Section titled “Headers”| Name | Type | Required | Description |
|---|---|---|---|
X-API-KEY | String | Yes | API key |
Content-Type | String | Yes | Must be application/json |
| Name | Type | Required | Description |
|---|---|---|---|
access_limit | Integer | No | Override default number of downloads |
description | String | Yes | Description of the package |
name | String | Yes | Name of the package |
password | String | No | Password required to download |
recipients | String[] | Yes | Email address of recipient(s) |
unlimited_storage | Boolean | No | Enable unlimited extended storage |
chunk_size | Integer | No | Chunk size in bytes for all file uploads in this package |
Request
Section titled “Request”curl -d '{"access_limit":$ACCESS_LIMIT, "description":"$DESCRIPTION", "name":"$NAME", "password": "$PASSWORD", "recipients":["$RECIPIENT_EMAIL"]}' \ -H "X-API-KEY: $API_KEY" \ -H "Content-Type: application/json" \ -X POST https://api.massive.app/v1/teams/$TEAM_ID/packagesResponse
Section titled “Response”Returns 201 Created with the package object including id and access_token.
B. Portal package
Section titled “B. Portal package”| Method | Route |
|---|---|
POST | /portals/{portal_id}/packages |
Headers
Section titled “Headers”| Name | Type | Required | Description |
|---|---|---|---|
Content-Type | String | Yes | Must be application/json |
X-Access-Code | String | No | URI encoded upload password (if required by Portal settings) |
| Name | Type | Required | Description |
|---|---|---|---|
description | String | Yes | Description of the package |
name | String | Yes | Name of the package |
sender | String | Yes | Email address of the Portal package sender |
form_data_id | String | No* | Form response ID. *Required if the Portal has an enabled custom form. |
chunk_size | Integer | No | Chunk size in bytes |
2) Add a file to the package
Section titled “2) Add a file to the package”| Method | Route |
|---|---|
POST | /packages/{package_id}/files |
Headers
Section titled “Headers”| Name | Type | Required | Description |
|---|---|---|---|
X-Package-Token | String | Yes | Package JSON Web Token |
Content-Type | String | Yes | Must be application/json |
| Name | Type | Required | Description |
|---|---|---|---|
kind | String | Yes | Type of file: file or directory |
name | String | Yes | File name |
path | String | Yes | File’s relative path |
last_modified | String | Yes | File’s last modified date (UTC) |
size | Integer | No | File size in bytes (strongly recommended) |
chunk_size | Integer | No | Override the package-level chunk size |
Request
Section titled “Request”curl -d '{"kind":"file", "name":"my_video.mpeg", "path": "", "last_modified":"2018-12-17T16:14:34.450Z"}' \ -H "X-Package-Token: $PACKAGE_TOKEN" \ -H "Content-Type: application/json" \ -X POST https://api.massive.app/v1/packages/$PACKAGE_ID/filesResponse
Section titled “Response”Returns 201 Created with create_blueprint and file objects.
3) Create the file in MASV’s cloud storage
Section titled “3) Create the file in MASV’s cloud storage”Use the create_blueprint from step 2 to construct an HTTP request to the cloud storage service. The response will be XML containing an UploadId needed for subsequent steps.
4) Obtain upload URLs
Section titled “4) Obtain upload URLs”Request pre-signed upload URLs for each of a file’s parts.
| Method | Route |
|---|---|
POST | /packages/{package_id}/files/{file_id}?start={start}&count={count} |
Headers
Section titled “Headers”| Name | Type | Required | Description |
|---|---|---|---|
X-Package-Token | String | Yes | Package JSON Web Token |
Content-Type | String | Yes | Must be application/json |
| Name | Type | Required | Description |
|---|---|---|---|
upload_id | String | Yes | ID for the initiated multi-part upload |
Query parameters
Section titled “Query parameters”| Name | Type | Required | Description |
|---|---|---|---|
start | Integer | Yes | Starting index of the chunk (zero-indexed) |
count | Integer | Yes | Number of chunk requests to generate |
Request
Section titled “Request”curl -d '{"upload_id":"$UPLOAD_ID"}' \ -H "X-Package-Token: $PACKAGE_TOKEN" \ -H "Content-Type: application/json" \ -X POST "https://api.massive.app/v1/packages/$PACKAGE_ID/files/$FILE_ID?start=$START&count=$COUNT"Response
Section titled “Response”Returns an array of blueprints in ascending order based on the chunk index.
5) Upload the file chunks
Section titled “5) Upload the file chunks”Use each blueprint to upload the corresponding chunk as binary data in the request body.
curl -X PUT "$BLUEPRINT_URL" \ --data-binary @<(dd if=my_video.mpeg skip=0 count=104857600 iflag=skip_bytes,count_bytes)6) Publish upload progress
Section titled “6) Publish upload progress”MASV integrates with PubNub to indicate overall file upload progress on each package.
7) Finalize the file
Section titled “7) Finalize the file”Once all chunks have been uploaded, inform the API that the file upload is complete.
| Method | Route |
|---|---|
POST | /packages/{package_id}/files/{file_id}/finalize |
Headers
Section titled “Headers”| Name | Type | Required | Description |
|---|---|---|---|
X-Package-Token | String | Yes | Package JSON Web Token |
Content-Type | String | Yes | Must be application/json |
| Name | Type | Required | Description |
|---|---|---|---|
chunk_extras | Object[] | Yes | Information about all chunks |
chunk_extras[].part_number | String | Yes | Chunk part number |
chunk_extras[].etag | String | Yes | Chunk part hash |
file_extras.upload_id | String | Yes | The upload ID from step 3 |
size | Integer | Yes | The file size |
chunk_size | Integer | Recommended | The chunk size used when uploading |
Request
Section titled “Request”curl -d '{"chunk_extras":[{"part_number":"1","etag":"\"7be1b3cc95a04a6dd07d157ad6fae64a\""}], "file_extras":{"upload_id":"$UPLOAD_ID"}, "size":$FILE_SIZE, "chunk_size":$CHUNK_SIZE}' \ -H "X-Package-Token: $PACKAGE_TOKEN" \ -H "Content-Type: application/json" \ -X POST https://api.massive.app/v1/packages/$PACKAGE_ID/files/$FILE_ID/finalizeResponse
Section titled “Response”Returns 204 No Content.
8) Finalize the package
Section titled “8) Finalize the package”Once all files have been uploaded and finalized, indicate that the package is ready to be dispatched.
| Method | Route |
|---|---|
POST | /packages/{package_id}/finalize |
Headers
Section titled “Headers”| Name | Type | Required | Description |
|---|---|---|---|
X-Package-Token | String | Yes | Package JSON Web Token |
Content-Type | String | Yes | Must be application/json |
Request
Section titled “Request”curl -H "X-Package-Token: $PACKAGE_TOKEN" \ -H "Content-Type: application/json" \ -X POST https://api.massive.app/v1/packages/$PACKAGE_ID/finalizeResponse
Section titled “Response”Returns 204 No Content.
Creating additional links
Section titled “Creating additional links”MASV’s API allows you to create additional direct-download links or send a link to a specific email recipient after the upload has been finalized. See the Links page for more details.