Sample code for 30+ languages & platforms
React Native

S3 Delete File

See more Amazon S3 Examples

Demonstrates how to delete a remote file (object) on the Amazon S3 service.

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 access key here:
  http.awsAccessKey = 'AWS_ACCESS_KEY';

  // Insert your secret key here:
  http.awsSecretKey = 'AWS_SECRET_KEY';

  const bucketName = 'chilkattest';
  const objectName = 'starfish.jpg';

  http.keepResponseBody = true;

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

  if (http.lastStatus !== 204) {
    console.log(`Status code = ${http.lastStatus}`);
    console.log(http.lastResponseBody);
    console.log('Failed.');
    return;
  }

  // 204 is the success response status.
  // When successful, the response body will be empty.
  console.log(`Status code = ${http.lastStatus}`);
  console.log('Success. Object deleted.');
}