+ Start a Discussion
Integrator9Integrator9 

Delete Object from Amazon s3Bucket Query Authentication or HTTP Call Out

Hi I am Trying to Delete a Object/ file from my Amazon S3 Bucket using following class

 

But i am facing issues with Signature.

 

Looking for any Help/ Suggestions

 

Public Class FD{

Public String SECRETACCESSKEY {get;set;}
Public String KEY {get;set;}
Public String BUCKET {get;set;}
Public String SIGNATURE {get;set;}
Public String FILENAME {get;set;}
Public String STRINGTOSIGN {get;set;}
Public String policy {get;set;}

datetime expire = DateTime.now().addSeconds(10);

long epochexpire=(expire.gettime()/1000);

String formattedexpire = expire.formatGmt('yyyy-MM-dd')+'T'+

expire.formatGmt('HH:mm:ss')+'.'+expire.formatGMT('SSS')+'Z';
Public string redirectURL{get;set;}

Public string documentPath {get;set;}

Public pagereference FD(){


SECRETACCESSKEY = 'mysecret';
KEY ='mykey' ;
BUCKET ='mybucket';
FILENAME ='a00U000000446as.docx';

String HIDATE = 'Fri, 12 Oct 2012 15:02:13 GMT';


policy ='DELETE\n\n\n'+(expire.gettime()/1000)+'\nx-amz-date:'+HIDATE+'\n/'+Bucket+'/'+filename;
System.debug('canonical = ' + policy );
Blob bsig = Crypto.generateMac('HmacSHA1', Blob.valueOf(policy), Blob.valueOf(SECRETACCESSKEY));


signature = EncodingUtil.base64Encode(bsig);

System.debug('SIGNATURE = ' + signature);


documentPath='https://s3.amazonaws.com/'+Bucket+'/';

redirectURL=documentPath+filename+'?x-amz-date='+HIDATE+'&AWSAccessKeyId='+key+'&Signature='+Signature+'&Expires='+epochexpire;



pagereference p=new pagereference(redirectURL);
system.debug('....path.....'+p);
System.debug('epochtime'+epochexpire);
p.setRedirect(true);
return p;
}

 

}

 

 

Thanks in advance

Best Answer chosen by Admin (Salesforce Developers) 
Integrator9Integrator9

Figured the Problem My self