Sample code for 30+ languages & platforms
Dart

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 Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

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

  final http = CkHttp();

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

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

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

  try {
    http.s3UploadFile(localFilePath, contentType, bucketName, objectName);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

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