Sample code for 30+ languages & platforms
React Native

S3 Upload a File with Public Read Permissions

See more Amazon S3 Examples

Demonstrates how to upload a file to the Amazon S3 service with the x-amz-acl request header set to "public-read" to allow the file to be publicly downloadable.

Chilkat React Native Downloads

React Native
import { Http } from '@chilkat/react-native'

async function chilkatExample() {
  // This example assumes the Chilkat HTTP API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  const http = new Http();

  // Insert your AWS keys here:
  http.awsAccessKey = 'AWS_ACCESS_KEY';
  http.awsSecretKey = 'AWS_SECRET_KEY';

  const bucketName = 'chilkat.ocean';
  const objectName = 'seahorse.jpg';
  const localFilePath = 'qa_data/jpg/seahorse.jpg';
  const contentType = 'image/jpg';

  // Add the x-amz-acl request header to make the file publicly readable.
  http.setRequestHeader('x-amz-acl', 'public-read');

  try {
    await http.s3UploadFileAsync(localFilePath, contentType, bucketName, objectName);
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  if (http.lastStatus === 200) {
    console.log('File uploaded.');
  } else {
    console.log(`Response status code: ${http.lastStatus}`);
    console.log(http.lastResponseBody);
  }
}