Skip to main content
Skip table of contents

initializeUpload

This method is used to initialize attachment uploads.

Refer to Uploading Files to S-Drive (Amazon S3) for comprehensive instructions on how to upload files using SDriveTools API.


List<UploadRequestInfo> initializeUpload
(String objectId, List<SObject> attachments, Map<String,String> policyMap)


Parameters:
objectId: Id of the parent object. You can use 15-character or 18-character Salesforce.com 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:
http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPOST.html
Return Value: The method will return the list of UploadRequestInfo (see table below), which holds information about the files that are about to be uploaded.

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 reference Figure 9 and Returns a list of UploadRequestInfo
    objects.

Example Code

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);
attachments.add(attachment);
Map<String, String> policyMap= new Map<String,String>();
policyMap.put('$Content-Disposition','attachment; filename');
List<cg.UploadRequestInfo> uploadRequestInfos=
cg.SDriveTools.initializeUpload(objectId ,attachments, policyMap );


Notes:

  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

Value

acl
Content-Disposition
Content-Type
key
policy
x-amz-server-side-encryption
x-amz-credential
x-amz-date
x-amz-algorithm
x-amz-signature
success_action_status

private'
'attachment; filename="'+ uploadRequestInfos.fileName+'"'
uploadRequestInfos.fileType
uploadRequestInfos.fileLocation
uploadRequestInfos.policy
'AES256'
uploadRequestInfos.awsCredential
uploadRequestInfos.timeStamp
'AWS4-HMAC-SHA256’
uploadRequestInfos.signature
201

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.