File Upload/Download to S3 Bucket

The following endpoints allow you to upload, download, or delete files on S3.  The User Portal can be linked to two separate S3 buckets, referred to as private and public S3 buckets. 

 

Notes:

There is an upload limit of 1 MB.

AWS serves some filetypes, such as SVG, with the wrong Content-Type. This means that if you upload a file of this type to your S3 bucket, you will not be able to display the file correctly on your portal without some adjustments on AWS. If this happens to you, please reach out to us at support@mediumone.com for assistance.

 

Private S3 Bucket

The files uploaded to the private S3 can only be downloaded by the account that uploaded it (note: this is an account-based permission - NOT user-based). Files uploaded by a Super Admin on a Super Admin page will only be allowed to be downloaded by Super Admin. Files uploaded by a Super Admin on an Account page will belong to that account.

 

Public S3 Bucket

The files uploaded to the public S3 bucket can be downloaded by any tenant. You can optionally provide public S3 permissions to the public bucket to share the file URLs outside of the User Portal.

 

Note:

Older S3 endpoints media_s3_upload, media_s3_download, and media_s3_delete are deprecated and we recommend migrating to this endpoint.

 

Prerequisite

Set up the following S3 keys in the Advanced Config:

  • S3_ACCESS_KEY : Access key for the private S3 file endpoints. Required in order to upload, download, or delete private S3 files.

  • S3_SECRET_KEY: Secret key for the private S3 file endpoints. Required in order to upload, download, or delete private S3 files.

  • S3_BUCKET: Bucket for the private S3 file endpoints. Required in order to upload, download, or delete private S3 files.
  • S3_PUBLIC_ACCESS_KEY : Access key for the public S3 file endpoints. Required in order to upload, download, or delete public S3 files.

  • S3_PUBLIC_SECRET_KEY: Secret key for the public S3 file endpoints. Required in order to upload, download, or delete public S3 files.

  • S3_PUBLIC_BUCKET: Bucket for the public S3 file endpoints. Required in order to upload, download, or delete public S3 files.
  • S3_PUBLIC_BASE_URL: This is an optional key that provides the base URL for public files so that public file download is faster.

 

Upload File

This endpoint is used by any user to upload a file.   

 

Summary

  • Endpoint: /file_upload
  • Method: POST
  • Required User Type: None, any user can use this

Body Parameters

  • data (required): string representation of the file
  • name (required): file name
  • bucket_type (required): either "public" or "private"

Response

{"file_key":<file key>}

The file_key is required to download or delete the file.

 

Note: if you were using the deprecated media_s3 endpoints, those returned media_key - you will have to adjust your code to handle file_key instead.

 

Example

Request Body

{
"data":"data:image/png;base64,iVBOR...",
"name":"desktopviewtest.png",
"bucket_type":"public"
}

Response Data

{"file_key": "31e5d9d7-8efd-41f4-a3ee-b77dc2a551ac"}

 

Download File

This endpoint is used by any user to download a file.   

 

Summary

  • Endpoint: /file_download/{bucket_type}/{file_key}
  • Method: GET
  • Required User Type: None, any user can use this as long as they have permissions to view this file

URL Parameters

  • bucket_type (required): "public" or "private"
  • file_key (required): the key returned when file was uploaded

Response

A successful response will return file

 

Example

Request URL

https://portal-example.mediumone.com/file_download/private/f22819ca-f895-45f7-830b-f5ba390f6735.png

 

Delete File

This endpoint is used by any user to delete a file.

Summary

  • Endpoint: /file_delete
  • Method: POST
  • Required User Type: None, any user can use this as long as they have permissions to view this file

JSON Body

  • bucket_type (required): "public" or "private"
  • file_key (required): the key returned when file was uploaded

Response

{"success":true}

 

Example

Request Body

{
file_key: "f22819ca-f895-45f7-830b-f5ba390f6735",
bucket_type: "public"
}

Response Data

{"success": true}