function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
tmax8200tmax8200 

Amazon S3 Delete Example

Hello,

 

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,
                           file_name__c,
                           file_ID__c,
                           matter_number__c,
                           client_number__c,
                           fileURL__c
                    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('Host','xxxx.s3.amazonaws.com');

    con.setHeader('Date', dateString);
    con.setMethod('DELETE');
    
    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.

 

Thanks!

 

Max

Charlie9Charlie9

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

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

 1. Create Amazon S3 file for standard Salesforce attachment through
    trigger.
 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.

https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000CW1OXEA1

Here is our email address. Let us know if you have any query.
support@neiloncloud.com

Thanks.
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:

https://zappysys.com/products/ssis-powerpack/ssis-amazon-s3-task/

Hope this Helps!