• Jason Flammang
  • NEWBIE
  • 85 Points
  • Member since 2014

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

I need to create folder under bucket on amazon s3 through REST webservice in salesforce .I am getting 503 as status code .Below is my REST class.Please do help

global with sharing class SalesForceAmazonWebservices{

 public void s3RestPut() { 
  
  String Date1 =  Datetime.now().formatGMT('EEE,   dd MMM yyyy HH:mm:ss z');
  String filename = 'test3';
  String bucketname = 'Bucket1';
  String Method = 'PUT';
  HttpRequest req = new HttpRequest();
  req.setMethod(method);

 
  
  req.setEndpoint('http://aws-us-west-2.amazon.com/s3/'+  bucketname + '/' + filename);
  req.setHeader('HOST','aws-us-west-2.amazon.com/s3/'); 
  req.setHeader('content-type', filename);
  req.setHeader('content-Encoding', 'base64');
  req.setHeader('Date',Date1);
 
 
  String stringToSign = 'PUT\n\n\n'+Date1+'\n/'+bucketname+'/'+filename + '/' ;  

  Blob mac = Crypto.generateMac('HMacSHA1', blob.valueof(stringtosign),blob.valueof('*******************'));

      String signature = EncodingUtil.base64Encode(mac);
   
        String authHeader = 'AWS'  + '**************' + ':' + signature  ;
        req.setHeader('Authorization',authHeader);  
        req.setBody(filename);
        Http http = new Http()
        HTTPResponse res = http.send(req);
        
    }
}
I have a need to upload binary stream PDF files to Amazon S3.  I've seen the sample code available to use the REST API with the POST operation on visualforce page, however, I need to upload the file via APEX without user involvment, as I'm retrieiving the files from another database via their SOAP API.

I'm trying to do this using the PUT operation, but I don't think I'm doing the authentication correctly as I'm getting a 403 Forbidden response.

Any ideas?
 
public void uploadPDF(String binaryPdfString, String key, String secret){
        String Date = Datetime.now().formatGMT('EEE,   dd MMM yyyy HH:mm:ss z');
        String bucketname = 'BucketName';
        String method = 'PUT';
        String filename = 'FileName';
        HttpRequest req = new HttpRequest();
        req.setMethod(method);
        req.setHeader('Host','s3-us-west-2.amazonaws.com');
        req.setEndpoint('https://s3-us-west-2.amazonaws.com' + '/'+ bucketname + '/' + filename);
        req.setHeader('Content-Length', string.valueOf(binaryPdfString.length()));
        req.setHeader('Content-Encoding', 'base64');
        req.setHeader('Content-Type', 'pdf');
        req.setHeader('Date', Date);

        //get signature string
        String stringToSign = 'PUT\n\n\n'+formattedDateString+'\n\n/'+bucketname+'/'+filename;
        String encodedStringToSign = EncodingUtil.urlEncode(stringToSign,'UTF-8');
        String signed = createSignature(encodedStringToSign,secret);
        String authHeader = 'AWS' + ' ' + key + ':' + signed;
        req.setHeader('Authorization',authHeader);
        req.setBody(binaryPdfString);
        Http http = new Http();

        try {
            //Execute web service call
            HTTPResponse res = http.send(req);
            System.debug('RESPONSE STRING: ' + res.toString());
            System.debug('RESPONSE STATUS: '+res.getStatus());
            System.debug('STATUS_CODE: '+res.getStatusCode());

        } catch(System.CalloutException e) {
            system.debug('AWS Service Callout Exception: ' + e.getMessage());
        }

}

public string createSignature(string canonicalBuffer,String secret){
        string sig;
        Blob mac = Crypto.generateMac('HMacSHA1', blob.valueof(canonicalBuffer),blob.valueof(secret));
        sig = EncodingUtil.base64Encode(mac);

        return sig;

}

 
Hello,

I need to create folder under bucket on amazon s3 through REST webservice in salesforce .I am getting 503 as status code .Below is my REST class.Please do help

global with sharing class SalesForceAmazonWebservices{

 public void s3RestPut() { 
  
  String Date1 =  Datetime.now().formatGMT('EEE,   dd MMM yyyy HH:mm:ss z');
  String filename = 'test3';
  String bucketname = 'Bucket1';
  String Method = 'PUT';
  HttpRequest req = new HttpRequest();
  req.setMethod(method);

 
  
  req.setEndpoint('http://aws-us-west-2.amazon.com/s3/'+  bucketname + '/' + filename);
  req.setHeader('HOST','aws-us-west-2.amazon.com/s3/'); 
  req.setHeader('content-type', filename);
  req.setHeader('content-Encoding', 'base64');
  req.setHeader('Date',Date1);
 
 
  String stringToSign = 'PUT\n\n\n'+Date1+'\n/'+bucketname+'/'+filename + '/' ;  

  Blob mac = Crypto.generateMac('HMacSHA1', blob.valueof(stringtosign),blob.valueof('*******************'));

      String signature = EncodingUtil.base64Encode(mac);
   
        String authHeader = 'AWS'  + '**************' + ':' + signature  ;
        req.setHeader('Authorization',authHeader);  
        req.setBody(filename);
        Http http = new Http()
        HTTPResponse res = http.send(req);
        
    }
}
I have a need to upload binary stream PDF files to Amazon S3.  I've seen the sample code available to use the REST API with the POST operation on visualforce page, however, I need to upload the file via APEX without user involvment, as I'm retrieiving the files from another database via their SOAP API.

I'm trying to do this using the PUT operation, but I don't think I'm doing the authentication correctly as I'm getting a 403 Forbidden response.

Any ideas?
 
public void uploadPDF(String binaryPdfString, String key, String secret){
        String Date = Datetime.now().formatGMT('EEE,   dd MMM yyyy HH:mm:ss z');
        String bucketname = 'BucketName';
        String method = 'PUT';
        String filename = 'FileName';
        HttpRequest req = new HttpRequest();
        req.setMethod(method);
        req.setHeader('Host','s3-us-west-2.amazonaws.com');
        req.setEndpoint('https://s3-us-west-2.amazonaws.com' + '/'+ bucketname + '/' + filename);
        req.setHeader('Content-Length', string.valueOf(binaryPdfString.length()));
        req.setHeader('Content-Encoding', 'base64');
        req.setHeader('Content-Type', 'pdf');
        req.setHeader('Date', Date);

        //get signature string
        String stringToSign = 'PUT\n\n\n'+formattedDateString+'\n\n/'+bucketname+'/'+filename;
        String encodedStringToSign = EncodingUtil.urlEncode(stringToSign,'UTF-8');
        String signed = createSignature(encodedStringToSign,secret);
        String authHeader = 'AWS' + ' ' + key + ':' + signed;
        req.setHeader('Authorization',authHeader);
        req.setBody(binaryPdfString);
        Http http = new Http();

        try {
            //Execute web service call
            HTTPResponse res = http.send(req);
            System.debug('RESPONSE STRING: ' + res.toString());
            System.debug('RESPONSE STATUS: '+res.getStatus());
            System.debug('STATUS_CODE: '+res.getStatusCode());

        } catch(System.CalloutException e) {
            system.debug('AWS Service Callout Exception: ' + e.getMessage());
        }

}

public string createSignature(string canonicalBuffer,String secret){
        string sig;
        Blob mac = Crypto.generateMac('HMacSHA1', blob.valueof(canonicalBuffer),blob.valueof(secret));
        sig = EncodingUtil.base64Encode(mac);

        return sig;

}

 
Hi ,

I'm new to integration . Have referred Salesforce documents but didnt understood much . I do not know where to start , I have a requirement to integrate Salesforce with Amazon S3 . So if anyone can help me with the sample code will be very useful . 

Also nice blogs ,useful links for integrations if given would be great.


Thanks,
Marc.

Hi,

 

I am new to Apex development and looking for some help with a simple trigger to delete erroneous opportunities created by an automated process.

 

Basically, we want to delete any opportunity that is created where the opportunity name = "..."

 

Thanks for any assistance!

  • March 09, 2012
  • Like
  • 0

Hi All,

 

I have some long text area fields in my VF page which is using Standard controller and extension.

I am using Standard save method in the action for Saving the record.

The long text area fields have character limit of 10000.

 

When I enter more than 10000 characters in the field and click Save, I am getting the following error message twice

 

"You can't use more than 10,000 characters"

I am not using pagemessage tag and there is no validation rule also.

This is happening in the sandbox instance which was recently refreshed with the new winter release 11.

 

Initially I thought there is some problem in the controller. So I tried to have only one field in the page with only Standardcontroller and no extension. Still it displays the error message twice.

Following is the code I am having in my VF page.

<apex:page standardController="Case" apiVersion="20">
<apex:form >
      <apex:pageBlock >
          <apex:pageBlockSection title="Problem Description Notes" id="pbs1" columns="1">
               <apex:inputField value="{!Case.Problem_Description__c}" style="width:300px"/>
          </apex:pageBlockSection>
      <apex:commandButton value="UpdateCase" action="{!Save}"/>
      </apex:pageBlock>
       
</apex:form>

</apex:page>

 

 

I am not getting what is the mistake here.

 

I tried the same thing in my developer instance which is still not refreshed with the new release.

There the error message is displayed only once.

So, I am not getting if this is a new release issue.

 

Please let me know your suggestions.

 

Thanks

Arvind

  • September 24, 2010
  • Like
  • 0