Sample code for 30+ languages & platforms
C

S3 Delete File

See more Amazon S3 Examples

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

Chilkat C Downloads

C
#include <C_CkHttp.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttp http;
    const char *bucketName;
    const char *objectName;

    success = FALSE;

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

    http = CkHttp_Create();

    //  Insert your access key here:
    CkHttp_putAwsAccessKey(http,"AWS_ACCESS_KEY");

    //  Insert your secret key here:
    CkHttp_putAwsSecretKey(http,"AWS_SECRET_KEY");

    bucketName = "chilkattest";
    objectName = "starfish.jpg";

    CkHttp_putKeepResponseBody(http,TRUE);
    success = CkHttp_S3_DeleteObject(http,bucketName,objectName);

    if (success != TRUE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        return;
    }

    if (CkHttp_getLastStatus(http) != 204) {
        printf("Status code = %d\n",CkHttp_getLastStatus(http));
        printf("%s\n",CkHttp_lastResponseBody(http));
        printf("Failed.\n");
        CkHttp_Dispose(http);
        return;
    }

    //  204 is the success response status.
    //  When successful, the response body will be empty.
    printf("Status code = %d\n",CkHttp_getLastStatus(http));
    printf("Success. Object deleted.\n");


    CkHttp_Dispose(http);

    }