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
Jamie ThompsonJamie Thompson 

How to move files from Salesforce to Amazon S3?

Hello everyone!

I am using Salesforce Community to develop a mobile application. I want to store files (file feeds) into Amazon S3 instead of Salesforce. Does anyone know how to do that? Any help would be much appreciated.
SonamSonam (Salesforce Developers) 
hi Jamie, Just wish to check if I understand this correctly - so you are trying to save the Chatter Files on a 3rd party rather than salesforce? or is it that the files will still be in Salesforce but you wish to access it in Amazon S3 as well(opposite of https://help.salesforce.com/apex/HTViewHelpDoc?id=admin_files_connect_overview.htm&language=en_US)
Jamie ThompsonJamie Thompson
Hi Sonam. Thanks for the reply.

Yes, I want to save Chatter Files on a 3rd party rather than Salesforce. The files will not be on SF.
S3-LinkS3-Link
S3- Link is FREE App for Salesforce - Amazon Connector. Its also available on Appexchange. 
 

    Attach file related to any Salesforce object on Amazon.
    Ulimited free storage for one year.
    Multiple file uplaod.
    No file size limit for upload.
    File access control capabiliy.
    Track file downloads by users.
    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.
Arun BhardwajArun Bhardwaj
User-added image       
 String today = Datetime.now().format('dd-MM-yyyy');
         Blob csvBlob = blob.valueOf(csvFile );
        // Blob csvBlob= EncodingUtil.base64Decode(csvFile);
        String csvName = ObjectLabelName+' Data as on '+today+'.csv';
        
        string filename,filetype='';
        String Sdate = Datetime.now().formatGMT('EEE,   dd MMM yyyy HH:mm:ss z');
        filename=ObjectLabelName +'.csv';
        //setup variables
        String formattedDateString = Datetime.now().format('EEE, dd MMM yyyy HH:mm:ss z','America/Denver');    //this is needed for the PUT operation and the generation of the signature.  I use my local time zone.
        String bucketname='datadrchiving/test';
        String method='PUT';
        String contentType = 'text/csv';
        HttpRequest req = new HttpRequest();
        req.setMethod(method);
        req.setHeader('Host','s3.console.aws.amazon.com');
        req.setEndpoint('https://s3.console.aws.amazon.com/s3'+'/'+'buckets'+'/'+bucketname);//+'/'+filename
        req.setHeader('Content-Length', string.valueOf(csvFile.length()));
        req.setHeader('Content-Type', contentType);
        req.setHeader('Content-Encoding','base64');
        req.setHeader('Date', formattedDateString);
        req.setHeader('ACL', 'public-read-write');
        String stringToSign = 'PUT\n\n' + formattedDateString + '\n\n' + '/' + bucketname + '/' + filename;
      //  String signed = createSignature(stringToSign,secret);
       // String authHeader = 'AWS' + ' ' + key + ':' + signed;
         string authHeader=createAuthHeader(method,contentType,filename,formattedDateString,bucketname,key,secret);
        system.debug('Auth header***');
        system.debug(authHeader);
        req.setHeader('Authorization',authHeader);
        system.debug('blob value***'+csvBlob);
        req.setBodyAsBlob(csvBlob);
        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());
        }

Response is coming 200 ok from AWS server  but unable to find the CSV in aws account. Could you please check and help on this. 
Kevin PoklertKevin Poklert
I had a successful experience in creating a direct connection between SFDC and Amazon with help of cloud-based service - Skyvia (https://skyvia.com/data-integration/integrate-salesforce-amazon-s3).
The service is totally no coding and has flexible scheduling features.
Sonam MeshramSonam Meshram
I came across the newly developed app in AppExchange named Drag, Drop & Upload Files to Amazon S3 for this am using the same and its very easy to understand and having advanced features like you can delete/view your files from salesforce, and also provide some additional customization .
Please have look:https://sforce.co/34y12sL