Introduction

In addition to basic IP messaging, Bit6 supports rich media attachments. While the message text and meta data is sent via Bit6 servers, the file attachments are stored in AWS S3 bucket.

When a client SDK sends a message with an attachment from a device, the attachment is uploaded directly to S3 without going through Bit6 servers. When the message is received, the attachment is downloaded to the device directly from the S3 bucket.

By default Bit6 platform stores the attachments in Bit6 AWS S3 bucket and the developer is charged for the storage space according to the developer's plan.

Depending on your requirements, you may want to store the attachment files in your own S3 bucket. The instructions below explain the necessary configuration steps.

AWS Configuration

S3 Bucket

  1. Go to AWS S3 Console

  2. Click Create Bucket to create a bucket (e.g. bit6-attach) that will store message attachments

S3 CORS Setup

For your attachments to be loaded correctly from the web browsers that use Bit6 JS SDK, you need to configure CORS for the bucket.

  1. Select the newly created bucket, click on Properties in the right column

  2. Under Permissions section, click on Edit CORS Configuration.

  3. In the text area that is shown, paste the code snippet below, then click Save

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>Authorization</AllowedHeader>
        <AllowedHeader>Content-type</AllowedHeader>
        <AllowedHeader>Origin</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

IAM User

Now we need to create an AWS user that has permissions to upload files to this bucket. Bit6 platform will connect to your S3 bucket authenticating as this user.

  1. Go to AWS IAM Console

  2. In the left menu select Users

  3. Click Create New Users

  4. Enter a username, for example, bit6-attach-user

  5. Make sure the checkbox Generate an access key for each user is checked

  6. Click Create

  7. In the next screen, click on Show User Security Credentials

  8. Copy the values for Access Key ID and Secret Access Key

User Policy

For security purposes we will limit this user's permissions ONLY to be able to upload files to this particular S3 bucket.

  1. In the Users list, click on the user you just created, i.e. bit6-attach-user

  2. In the main section, select Permissions tab

  3. Expand Inline Policies section, and click on the link appropriately titled click here

  4. In the next screen expand Custom Policy, click Select

  5. Enter any Policy Name, e.g. 'bit6-upload'

  6. In Policy Document paste the following text (replace bit6-attach with the name of the S3 bucket you want to use):

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Action": [
                    "s3:*"
                ],
                "Sid": "Stmt1377115414000",
                "Resource": [
                    "arn:aws:s3:::bit6-attach/*"
                ],
                "Effect": "Allow"
            }
        ]
    }
    
  7. Click Apply Policy

Bit6 Configuration

Dashboard

Select your app in the Dashboard

Click Settings in the left menu, then go to Attachments tab.

S3 bucket

Enter the required values:

Click Update.

Next time you run your Bit6-enabled app, it should upload the attachments to your S3 bucket.