This method is used to initialize attachment uploads.
List<UploadRequestInfo> initializeUpload
(String objectId, List<SObject> attachments, Map<String,String> policyMap)

objectId: Id of the parent object. You can use 15-character or 18-character id. For example, this ID is the ID of the case record if the attachments are being uploaded for a case.
attachments:List of Salesforce SObject for uploading. The SObject will be representing the "File" object. For example, for a Case attachment, the SObject will be representing the cg_CaseFile_c record.
policyMap: Map of policy conditions and theirs values that represent the additional policy parameters used during upload (e.g. ('$Content-Disposition', 'attachment; filename)). For more information, visit the Amazon documentation:
Return Value: The method will return the list of UploadRequestInfo , which holds information about the files that are about to be uploaded.


String fileSize{get; set;}
String fileType{get; set;}
String wipFileId{get; set;}
String signature{get; set;}
String policy{get; set;}

The following steps are executed within this method:

  1. Validate the input with the following rules:If the uploaded attachments are of type S3Object (i.e. files in S-Drive tab), the Parent__c field should be the same for all files.

  2. If the uploaded attachments are of type S3Object (i.e. files in S-Drive tab), there should not be an existing file with the same name in the same folder.

  3. File name and file size can't be blank

  4. File name can't include the following characters: \ / : * ? \" <> | ~

  5. File size can't be zero.

  6. File size can't be more than the Max file size defined in S-Drive Configuration.

  7. Create the file record in Salesforce with work in progress state (WIP__c = true) ( i.e. create
    S3Object, Case File, Custom Object File, etc).

  8. Calculate policy, signature, file name etc. in order to be used as the POST parameters. While
    calculating the policy, policyMap parameter is used to generate different parameters in the
    policy. For html upload please see below and Returns a list of UploadRequestInfo

Html Policy
"expiration": "2014-03-12T12:47:13.893Z",
{"acl": "private" },
{"bucket": "cg--81..." },
["starts-with", "$Content-Disposition", "attachment; filename"],
["starts-with", "$key", "a038…"],
{"x-amz-server-side-encryption": "AES256"},

Example Code

List<SObject>attachments = new List<SObject>();
My_Example_Object_File__c attachment = new My_Example_Object_File__c();
attachment.File_Name__c = 'Example.txt';
attachment.File_Size_in_Bytes__c ='100';
attachment.Parent__c = 'a0I80…';
String objectId = String.valueOf(attachment.Parent__c);
Map<String, String> policyMap= new Map<String,String>();
policyMap.put('$Content-Disposition','attachment; filename');
List<cg.UploadRequestInfo> uploadRequestInfos=
cg.SDriveTools.initializeUpload(objectId ,attachments, policyMap );


  1. It is required to set SObject’s File_Name__c, File_Size_in_Bytes__c and Parent__c
    fields. You can optionally set other custom fields.

  2. For S-Drive Attachments files, Parent__c refers to its parent object id. In order to set
    the parent folder id, use Parent_Folder_Id__c field. For S-Drive Folders files,
    Parent__c refers to its parent folder id and if you want to upload the file to home
    folder set this to null. Also for S-Drive Folders files, objectId must to be set to null.

  3. If you put expiration, acl, bucket, key and x-amz-server-side-encryption conditions in
    the policyMap, these parameters will be ignored. Because, these are being set in the
    initializeUpload () method. You do not need to put these parameters in the
    policyMap. But, you must use these parameters while uploading.

Form Field



'attachment;filename=\"'+ uploadRequestInfos.fileName+'\"'