• S3-Link
  • NEWBIE
  • -11 Points
  • Member since 2016
  • Neilon Technologies


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 35
    Replies
What is the best managed package for Amazon S3 connector?
I am trying to upload files from a lightning component to AWS directly with saving in salesforce. I get 400 Bad Request error.
Can anyone help?

 
public with sharing class TestingAmazon {
    @AuraEnabled
    
    public static String testIntegration(String filename, String base64Data , String contentType) {
        System.debug('filename---->>'+filename);
        System.debug('base64Data---->>'+base64Data);
        System.debug('contentType---->>'+contentType);
        //Blob beforeblob = EncodingUtil.base64Decode(base64Data);
        Blob beforeblob = Blob.valueOf(base64Data);
        String attachmentBody = EncodingUtil.base64Encode(beforeblob);
        String formattedDateString = Datetime.now().formatGMT('EEE, dd MMM yyyy HH:mm:ss z');
        String key = '-------------------------------';
        String secret = '---------------------------------------------';
        String bucketname = 'testfileupoad';
        String host = 's3.ap-south-1.amazonaws.com';
        String method = 'PUT';

        HttpRequest req = new HttpRequest();
        req.setMethod(method);
        req.setEndpoint('https://' + bucketname + '.' + host + '/' + bucketname + '/' + filename);

        req.setHeader('Host', bucketname + '.' + host);
        req.setHeader('Content-Length', String.valueOf(attachmentBody.length()));
        req.setHeader('Content-Encoding', 'base64');
        req.setHeader('Content-type', contentType);
        req.setHeader('Connection', 'keep-alive');
        req.setHeader('Date', formattedDateString);
        req.setHeader('ACL', 'public-read');
        req.setBodyAsBlob(beforeblob);
        System.debug('req---->'+req);
        
       /* String stringToSign = 'PUT\n\n' +
                contentType + '\n' +
                formattedDateString + '\n' +
                '/' + bucketname + '/' + bucketname + '/' + filename; */

        String stringToSign = 'PUT\n' +
                contentType + '\n' +
                formattedDateString + '\n' +
                '/' + bucketname + '/' + bucketname + '/' + filename;
        System.debug('stringToSign---->>'+stringToSign);

        String encodedStringToSign = EncodingUtil.urlEncode(stringToSign, 'UTF-8');
        Blob mac = Crypto.generateMac('HMACSHA1', blob.valueof(stringToSign),blob.valueof(secret));
        String signed = EncodingUtil.base64Encode(mac);
        String authHeader = 'AWS' + ' ' + key + ':' + signed;
        System.debug('authHeader---->>'+authHeader);
        req.setHeader('Authorization',authHeader);
        String decoded = EncodingUtil.urlDecode(encodedStringToSign , 'UTF-8');

        Http http = new Http();
        HTTPResponse res = http.send(req);
        System.debug('RESPONSE STRING: ' + res.toString());
        System.debug('RESPONSE STATUS: ' + res.getStatus());
        System.debug('STATUS_CODE: ' + res.getStatusCode());
        if(res.getStatusCode() == 200){
            String ReturnUrl = 'https://'+host+'/'+bucketname+'/'+bucketname+'/'+filename;
            System.debug('ReturnUrl---->>'+ReturnUrl);
            return ReturnUrl;
        }
        return 'ERROR';
    }
}

 
Hi Guys,

I have a custom list view VF button for mass action on my opportunity object. This works fine when I am using this on classic or Lightning experience.
Earlier there were no checkboxes for records within Napili template in list views and no button used to show up. In summer '17 release checkboxes and buttons are now showing up. But when I click on this button, wierdly enough nothing happens at all. My VF is lightning and Salesforce1 enabled. User has relevant permissions.
If anyone wants to check out this in their dev org for trial. Use this page for creating a list view button and add to layout.

This is very critical. Any pointers will be appreciated.

Apex class:
public class tenPageSizeExt {

    public tenPageSizeExt(ApexPages.StandardSetController controller) {
        controller.setPageSize(10);
    }
}

VF Page:
<apex:page standardController="Opportunity" recordSetVar="opportunities" tabStyle="Opportunity" extensions="tenPageSizeExt">
    <apex:form >
        <apex:pageBlock title="Edit Stage and Close Date" mode="edit">
            <apex:pageMessages />
            <apex:pageBlockButtons location="top">
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!selected}" var="opp">
                <apex:column value="{!opp.name}"/>
                <apex:column headerValue="Stage">
                    <apex:inputField value="{!opp.stageName}"/>
                </apex:column>
                <apex:column headerValue="Close Date">
                    <apex:inputField value="{!opp.closeDate}"/>
                </apex:column>
            </apex:pageBlockTable>      
        </apex:pageBlock>
    </apex:form>
    </apex:page>


Regards,
Nitish
Hi everyone,

I am trying to integrate my SalesForce and AWS accounts in order to move files I have stored in SalesForce into AWS. Is there a method for doing this?

Thank you!
Is there any method to export the attacments of custom object?
Hi,

I need to upload few images to Amazon S3storage. Can anyone help how can i achieve this with apex code.

thanks in advance..
I am using Apex REST to call Amazon S3.  I am trying to get the list of the content of a specific folder in a bucket.  The GET request returns all the content of the bucket but I would like to get just the content of a specific bucket.  I think I need to pass a Delimiter and/or a Prefix but not sure how to do this.  I tried this below but doesn't seem to have any effect.
     
       req.setHeader('Prefix','VHUB/INBOX/') ;       
       req.setHeader('Delimiter','/');                        
 
public AWS_Keys__c awsKeySet;
public String bucketname1 = BUCKETNAME; 
public String key1=KEY;
public String secret1=SECRET;
          
// public void readGetFromVirtualS3(){   
         //this is needed for the PUT operation and the generation of the signature.  I use my local time zone.        
        String formattedDateString1 = Datetime.now().format('EEE, dd MMM yyyy HH:mm:ss z','America/Los_Angeles');   
        
        String method1 = 'GET';
        HttpRequest req = new HttpRequest();
        Http http = new Http();
        String filename1 =''; //'500/' ; 
        //String filename = 'VHUB/INBOX/' ;

        req.setEndpoint('https://'+ bucketname1 +'.s3.amazonaws.com' +'/'+ filename1);   
     /********   req.setHeader('Prefix','VHUB/INBOX/') ;		********/
   /********	req.setHeader('Content-Type', ''); 			
  	 		req.setHeader('Delimiter','/');				********/

        req.setMethod(method1);
        req.setHeader('Date', formattedDateString1);
        req.setHeader('Authorization',createAuthHeader(method1,filename1,formattedDateString1,bucketname1,key1,secret1));
         //Execute web service call
            try {
                HTTPResponse res = http.send(req);
                System.debug('MYDEBUG: ' + ' RESPONSE STRING: ' + res.toString());
                System.debug('MYDEBUG: ' + ' RESPONSE STATUS: '+ res.getStatus());
                System.debug('MYDEBUG: ' + ' STATUS_CODE:'+ res.getStatusCode());
                System.debug('MYDEBUG: ' + ' GET_BODY:'+ res.getBody());
                XmlStreamReader reader = res.getXmlStreamReader();
                System.debug(reader.getLocalName());
                
            } catch(System.CalloutException e) {
                system.debug('MYDEBUG: AWS Service Callout Exception on ' + 'ERROR: ' + e.getMessage());
            }
 //   }

  	 //create authorization header for Amazon S3 REST API
    public string createAuthHeader(String method,String filename,String formattedDateString,String bucket,String key,String secret){
        string auth;
        String stringToSign = method+'\n\n\n'+formattedDateString+'\n/'+bucket +'/'+filename;
        Blob mac = Crypto.generateMac('HMACSHA1', blob.valueof(stringToSign),blob.valueof(secret));
        String sig = EncodingUtil.base64Encode(mac);
        auth = 'AWS' + ' ' + key + ':' + sig;
        return auth;
    }

The code returns all the folders and files in the bucket but I need to pass a parameter to only return the content of one folder.


 
I want to upload large files to S3 server from visualforce page. How can we achieve this? Now I am able to upload small files. Any help?
I have developed an application to integrate with Amazon S3 server. I have completed it successfully. I want to do the secure callouts from salesforce to Amazon S3 using the Self-signed and CA-Signed certificate. I have tried with the Self-Signed certificate, but I was unable to do the secure callouts. Can any one help me to do the secured callouts from Salesforce to S3.  I went through the following link " http://wiki.developerforce.com/page/Making_Authenticated_Web_Service_Callouts_Using_Two-Way_SSL ", but it is not working as expected. 

I have created same application in 2 orgs and created Self signed certificate from one org and added that certificate in S3. But still I was able to do the callouts from 2 orgs and able to get the data from 2 orgs. Can you help me to resolve this issue?
Hi Experts,

I am trying to upload a file on S3. I have been verified everything couple of times and all looks correct to me, but whenever I am trying to upload file, getting error message saying

<Br/>
responseText =
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>InvalidArgument<BR/><Message>POST requires exactly one file upload per request.</Message><BR/><ArgumentValue>0</ArgumentValue><BR/><ArgumentName>file</ArgumentName><BR/><RequestId>3670E4EE52B3BCD5</RequestId><BR/><HostId>b3rOF/9WJHymo1ZENIOlrct/ZusAJ50AnSIP0df3K3+DdEcAFolJDx8qU6DH2N1l</HostId><BR/></Error></Code>

Can someone please help me to findout what I am doing wrong here?

<body>
       
        <div id="s3-fileuploader" class="dropArea"></div>
       
        <script type="text/javascript">

            j$ = jQuery.noConflict();

            //block and unblock UIbased on endpoint url
            function setUI(){
                j$('div.dropArea').unblock();
            }

            $(document).ready(function () {
           
                $('#s3-fileuploader').fineUploader({
               
                    request: {
                        endpoint: "https://{!bucketname}.s3.amazonaws.com",
                        accessKey: "{!key}"
                    },
                    signature: {
                       
                        //always included
                        "expiration": "{!expireStr}",
                       
                        signature : "{!signedPolicy}",
                        policy: "{!policy}",

                        "conditions":
                        [
                            //always included
                            {"acl": "public-read"},
                    
                            //always included
                            {"bucket": "{!bucketname}"},
                    
                            //not included in IE9 and older or Android 2.3.x and older
                            {"Content-Type": "{!ContentType}"},
                    
                            //always included
                            {"key": "{!key}"},
                    
                            //always included
                            {"x-amz-meta-qqfilename": "{!URLENCODE('test.jpg')}"},
                        ]
                    },
                    cors: {
                        expected: true, //all requests are expected to be cross-domain requests
                        sendCredentials: false, //if you want cookies to be sent along with the request
                        allowXdr: true
                    },

                    autoUpload: true,
                    multiple:false,
                    debug: true,
                   
                    text: {
                        uploadButton: '<i class="icon-plus icon-white">Select Files</i> '
                    },    
                    uploadSuccess: {
                        endpoint: "{!redirectURL}"
                    }
                }).on('submit',function(event,id,name){

                    //set endpoint
                    console.log('https://{!bucketname}.s3.amazonaws.com');
                    $(this).fineUploader('setEndpoint','https://{!bucketname}.s3.amazonaws.com');

                });
                setUI();
            });

        </script>
    </body>

Hi,

 We have around 1000's of uploads done over the course of years and reaching our limit on storage. I can download the file but one file at a time is not a solution production wise. Please could you recommend on how to achieve downloading/exporting the pdf's to computer in a bulk method. 

 

Thanks.

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

Does anyone have any advice on downloading a "private" file stored on Amazon S3, using an Apex method?  I partially understand how to pass a an authenticated request using web services, but I don't know how to "get" the file..  Any suggestions are welcome!!

  • September 27, 2010
  • Like
  • 0

Does anyone have any examples of how to call the Amazon S3 Rest API http://docs.amazonwebservices.com/AmazonS3/latest/RESTObjectOps.html

 

I know how to use the AWS SOAP examples but not all of the S3 API is available via SOAP so I would prefer to use REST.  Any pointers.  As all my code currently returns  status code 403 Forbidin 

  • March 24, 2010
  • Like
  • 0

Hello,

 

I've just installed Force.com for Amazon Web Services and I'm trying to get the samples to work.

With S3 Samples, I can create a bucket and then upload files.  But, when I try to display them by clicking on the link, I get the error: SignatureDoesNotMatch

 

Message: The request signature we calculated does not match the signature you provided. Check your key and signing method.

 

It's coming from the redirectToS3Key() method in the AWS_S3_ExampleController class.

 

Thanks in advance.

 

 

  • November 17, 2009
  • Like
  • 0

Hi,

 

I am trying to integrate Amazon S3 and salesforce. I have created an Apex class from the S3 WSDl using WSDL2Apex. When the S3 copyObject method is invoked, I get the following exception 

 

System.CalloutException: Web service callout failed: Unable to parse callout response. Apex type not found for element http://s3.amazonaws.com/doc/2006-03-01/=CopyObjectResponse

  

 

However, the object copy from one bucket to another is successful. Can somebody help me with understanding this exception?

 

I tried debugging the using Force.com IDE and the response seems to be the one expected for a successful COPY operation.

 

 

 

  

Message Edited by trish on 03-03-2009 10:52 PM
  • March 04, 2009
  • Like
  • 0
Hi..
I am trying to install and use the Amazon Toolkit .
 
the link to view it is :
 
 
I have created an account with Amazon.
In the AWS Credentials I have given the Credential name, the access key and the Secret.
 
When I click on the S3 Samples tab I am getting the following error:
 

Error:

 Web service callout failed: WebService returned a SOAP Fault: Your account is not signed up for the S3 service. You must sign up before you can use S3. faultcode=soapenv:Client.NotSignedUp faultactor=
 
 
When I click on the EC2 Console tab I am getting the following error:
 

Error:

 Error when querying the AWSKey__c custom object. Did not find any record with name of [force_demo_ag]. Please make sure the name is correct or create a record with the proper AWS credentials and retry.
 
Please guide me how to fix these errors.
 
Regards,
Diti

 
 
  • December 01, 2008
  • Like
  • 0
This is probably one for the guru's :

Is there any support for DIME attachments in Apex ? (I'm trying to achieve an 'Apex only' integration with Amazon S3)

So far a can list buckets, have users download files etc ... but for sending the files from the SFDC server to Amazon it looks my only valid option would be using DIME attachments in the SOAP calls.


David
Hi,


Does anyone know how to generate the correct signature for Amazon S3's soap services ?
I'm going with their docs :
http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?SOAPAuthentication.html

and so far I've got :

Code:
S3.AmazonS3 as3 = new S3.AmazonS3();
Datetime now = Datetime.now();


//format should be like 2006-01-01T12:00:00.000Z
String formattednow = now.formatGmt('yyyy-MM-dd')+'T'+now.formatGmt('HH:mm:ss')+'.000Z';
System.Debug('Formatted date : '+formattednow);

String canonical = 'AmazonS3'+'ListAllMyBuckets'+formattednow; //"AmazonS3" + OPERATION + Timestamp

System.debug('CANONICAL = '+canonical);

Blob bsig = Crypto.generateMac('HmacSHA1', Blob.valueOf(canonical), Blob.valueOf('myS3secretkey'));


String signature = EncodingUtil.base64Encode(bsig);

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

S3.ListAllMyBucketsResult result = as3.ListAllMyBuckets('myS3accesskey',now,signature);

 
I'm getting a SOAP exception back :
'SOAP Fault: The request signature we calculated does not match the signature you provided. Check your key and signing method.'


thanks,


David

Hi Guys,

I have a custom list view VF button for mass action on my opportunity object. This works fine when I am using this on classic or Lightning experience.
Earlier there were no checkboxes for records within Napili template in list views and no button used to show up. In summer '17 release checkboxes and buttons are now showing up. But when I click on this button, wierdly enough nothing happens at all. My VF is lightning and Salesforce1 enabled. User has relevant permissions.
If anyone wants to check out this in their dev org for trial. Use this page for creating a list view button and add to layout.

This is very critical. Any pointers will be appreciated.

Apex class:
public class tenPageSizeExt {

    public tenPageSizeExt(ApexPages.StandardSetController controller) {
        controller.setPageSize(10);
    }
}

VF Page:
<apex:page standardController="Opportunity" recordSetVar="opportunities" tabStyle="Opportunity" extensions="tenPageSizeExt">
    <apex:form >
        <apex:pageBlock title="Edit Stage and Close Date" mode="edit">
            <apex:pageMessages />
            <apex:pageBlockButtons location="top">
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!selected}" var="opp">
                <apex:column value="{!opp.name}"/>
                <apex:column headerValue="Stage">
                    <apex:inputField value="{!opp.stageName}"/>
                </apex:column>
                <apex:column headerValue="Close Date">
                    <apex:inputField value="{!opp.closeDate}"/>
                </apex:column>
            </apex:pageBlockTable>      
        </apex:pageBlock>
    </apex:form>
    </apex:page>


Regards,
Nitish