+ Start a Discussion

Amazon S3 Delete Example



I was hoping someone could post an example of a amazon s3 REST delete method that has worked. Does versioning need to be enabled for REST delete to work?


OR possibly spot whats wrong with this?



public pageReference deleteMode(){
    queryResults = [select ID,
                    from input_form__c
                    where ID = :inputFormID];
    input_form__c ifc = queryResults[0];

    fileURL = ifc.fileURL__c;

    String dateString = Datetime.now().formatGmt('EEE, dd MMM yyyy HH:mm:ss Z');

    stringToSign = 'DELETE\n' +
                   '\n' +
                   '\n' +
                   dateString + '\n' +
                   ('/xxxx' + fileURL).replaceAll(' ', '');

    //stringToSign = stringToSign.replaceAll(' ', '%20');

    System.debug('FINDME::stringToSign - ' + stringToSign);
    Blob mac = Crypto.generateMac('hmacSHA1',  Blob.valueOf(stringToSign), Blob.valueOf('xxxx'));
    stringToSign = EncodingUtil.base64Encode(mac);

    //String encoded = EncodingUtil.urlEncode(stringToSign, 'UTF-8'); 

    HttpRequest con = new HttpRequest();
    con.setHeader('Authorization','AWS xxxx:' + stringToSign);
    con.setEndPoint('http://xxxx.s3.amazonaws.com' + fileURL);

    con.setHeader('Date', dateString);
    Http http = new Http();
    HTTPResponse res = http.send(con);

    System.debug('RES.GETBODY: ' + res.getBody() + ' RES.GETSTATUS: ' + res.getStatus() + ' CON.GETENDPT: ' + con.getEndPoint());

    if (res.getStatusCode() >= 400) {
delete ifc;

return null;

res.getBody() is empty and res.getStatus is 'no content' which I think makes sense since its delete. But the file never gets deleted from s3.






Hi I am Facing the Similar Problem, Have you solved this , if so please guide me.

S3- Link is FREE App for Salesforce - Amazon Connector. Its also available on Appexchange. 

 1. Create Amazon S3 file for standard Salesforce attachment through
 2. Upload attachments on Amazon S3 and create reference in Salesforc to
    access those attachments
 3. Attach file related to any Salesforce object on Amazon.
 4. Unlimited free storage.
 5. Auto backup Event logs / inbound email attachments.
 6. Server Side Encryption: AES-256
 7. No file size limit for upload.
 8. File access control capabiliy.
 9. Track file downloads by users.
 10. File exlorer capability.


Here is our email address. Let us know if you have any query.

Nancy raiNancy rai
I am not expert but for 30+ Amazon S3 operations for S3 buckets and files (e.g. Download, Upload, Copy, Delete…) I will recommend you go through the following the link:


Hope this Helps!