• tmax8200
  • NEWBIE
  • 25 Points
  • Member since 2010

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 7
    Replies

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

Hi, I was hoping for some help changing the following psuedo code to apex.

 

Signature = URL-Encode( Base64( HMAC-SHA1( YourSecretAccessKeyID, UTF-8-Encoding-Of( StringToSign ) ) ) );

 

Heres what I've written so far, but theres something off:

 

stringToSign = EncodingUtil.urlEncode(stringToSign, 'UTF-8');
Blob mac = Crypto.generateMac('hmacSHA1',  Blob.valueOf(stringToSign), Blob.valueOf('xxx'));
stringToSign = EncodingUtil.base64Encode(mac);
String encoded = EncodingUtil.urlEncode(stringToSign, 'UTF-8');

Hi,

 

I'm trying to pass a parameter through the URL of a page doing a POST request. The parameter is the name of a file I'm uploading to amazon s3. I was hoping this would work  

 

CONTROLLER:

Public String fileName {get; set;}

 

VF:

<input type="hidden" name="success_action_redirect" value="xxx?q={!fileName}"/>

<input name="file" type="file" fileName="{!fileName}"/> 

 

but the parameter comes up blank on the next page. I get this error

 

<Error>
<Code>MaxPostPreDataLengthExceeded</Code>

<Message>
Your POST request fields preceeding the upload file was too large.
</Message>

 

when I try this

 

<input name="{!fileName}" type="file"/>

 

Thanks!

 

Max

Hi,

 

I am having difficulty immediately storing a parameter passed through a URL.

 

Here's the VF:

<input type="hidden" name="key" value="{!uniqueID}"/>

 

Here's the controller:

Public String uniqueID = System.currentPagereference().getParameters().get('q');

 

Here's the URL:

xxx.visual.force.com/apex/sendfilepage?q=xxx

 

Here's the error:

Unknown property 'sendFileController.UniqueID

 

The case is I am sending a file to amazon s3 online storage using a POST request and the URL parameter is the name of the file. This error persists until I write Public String uniqueID {get; set;} at which point I get a visualforce error saying I have two objects with the same name. It compiles when I comment out the original uniqueID. Any idea how to get around this without setting uniqueID within a new method? Or how to run a method immediately upon page loading?

 

Thanks!


Max

Hi,

 

I'm trying to pass a parameter through the URL of a page doing a POST request. The parameter is the name of a file I'm uploading to amazon s3. I was hoping this would work  

 

CONTROLLER:

Public String fileName {get; set;}

 

VF:

<input type="hidden" name="success_action_redirect" value="xxx?q={!fileName}"/>

<input name="file" type="file" fileName="{!fileName}"/> 

 

but the parameter comes up blank on the next page. I get this error

 

<Error>
<Code>MaxPostPreDataLengthExceeded</Code>

<Message>
Your POST request fields preceeding the upload file was too large.
</Message>

 

when I try this

 

<input name="{!fileName}" type="file"/>

 

Thanks!

 

Max

Hi,

 

I am having difficulty immediately storing a parameter passed through a URL.

 

Here's the VF:

<input type="hidden" name="key" value="{!uniqueID}"/>

 

Here's the controller:

Public String uniqueID = System.currentPagereference().getParameters().get('q');

 

Here's the URL:

xxx.visual.force.com/apex/sendfilepage?q=xxx

 

Here's the error:

Unknown property 'sendFileController.UniqueID

 

The case is I am sending a file to amazon s3 online storage using a POST request and the URL parameter is the name of the file. This error persists until I write Public String uniqueID {get; set;} at which point I get a visualforce error saying I have two objects with the same name. It compiles when I comment out the original uniqueID. Any idea how to get around this without setting uniqueID within a new method? Or how to run a method immediately upon page loading?

 

Thanks!


Max

I got the AmazonS3.wsdl from http://s3.amazonaws.com/doc/2006-03-01/AmazonS3.wsdl. But I get error meesage:

 

Error: Failed to parse wsdl: Unsupported Schema element found http://www.w3.org/2001/XMLSchema:include. At: 13:51

 

always! How do I fix this ? Lots of people seem to have done something to work around this issue.

 

Thanks

Rao

  • October 17, 2010
  • Like
  • 0