Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

You can use SDriveTools API calls for uploading the S-Drive Attachments/Folders Files to Amazon. For this, you will need to use below methods:


Before upload, you must first initialize attachment upload. Initializing the attachment upload creates work in progress (WIP) file(s) objects (S3Object, Case File, My Example Object File, etc.) and calculates the required file information for the upload process. For initializing attachment upload, use initializeUpload() method.
The next step is uploading the file(s) to Amazon using html upload. When you upload file(s) to Amazon, You should use the information which has been returned by initializeUpload() as well as the values retrieved from getAccessKeygetBucketName(), getBucketNamegetAmazonRegion() and getS3Endpoint() methods. If the region used is us-east-1, ten the value for region used will be s3.
If upload is successful, you must complete attachment upload. Complete attachment upload means updating WIP file records created during initialize upload call and set the WIPc field value as false. For completing attachment upload, use completeUpload() method.
If upload fails, you must cancel upload. Canceling upload means deleting the WIP file records. For canceling attachment upload, use cancelUpload() method.
You can also upload the big files using multipart uploads. For this, you will need below methods.

Html Policy

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


Exceptions and Reasons for Upload Operations

[SDriveException]"Parent Folder IDs must be the same for all file records that are being uploaded". 
[Reason] If Parent__c values which are passed in with the SObjects are not same for all S3Object.
[Solution] Give the parent folder ids the same for all S3Objects.

[SDriveException]"A file with the same name exists in the target folder (fileName) ".
[Reason] This exception occurs if a file with the same name exists in the same folder for S3Objects.The same file name condition holds when the file is not a WIP (WIP_c =false) file or the file is a WIP file (WIP_c =true) with the same file namebutithasbeenuploadedbyanotheruserlessthan12 hours ago.
[Solution]Upload files with different file names or delete the previously existing files before the upload.

[SDriveException]"Error occurred while checking the files to upload! File Name, File Size cannot be blank (fileName)".
[Reason]If the file name or file size fields that have been passed in with the SObject are null or empty.
[Solution]File name and file size is required for upload. Thus, pass non-blank values in with the SObject.

[SDriveException]"Name cannot start with a space or a dot and cannot contain any of the following characters: \\ /: ? \" < > |  (fileName)". 
[Reason]If the file name is invalid. Invalid name means, file name starts with a spaceor a dot and contains any of the following characters:  \ / :  ? \" < > | 
[Solution]Do not upload a file with the name starting with space or a dot and contain any of the following characters:  \ / : * ? \" < > | ~

[SDriveException]"You cannot upload a zero-length file (fileName)".  
[Reason] If the file size is 0. 
[Solution] Upload files that are greater in size than zero.

[SDriveException]"Files greater than (maxFileSize) cannot be uploaded. Please contact your system administrator for the file size limits! (fileName)".
[Reason]File being uploaded has a size greater than the maximum file size limit  (MAX_FILE_SIZE configuration in S-Drive Configuration page).
[Solution]Do not upload files whose size greater than MAX_FILE_SIZE. Or Increase the MAX_FILE_SIZE configuration in S-Drive Configuration page.

[SDriveException]"Invalid parent id specified. Check your function parameters!". 
[Reason] If object (parent) id, which is passed as a parameter, is not a Salesforce.com 15 or 18 characters long ID.
[Solution]Pass 15-character or 18-characterSalesforce.com ID as objectId parameter.

...

Error Messagesof ResultObject and Reasons

[errorMessage]"Wip Id is null! ". 
[Reason] If wipId in the wipIds list parameter is null.
[Solution] Do not pass null Salesforce.com IDs of file objects.

[errorMessage]"'No such wip file with provided id: (wipId) ".
[Reason]If wipId in wipIds list is not available.
[Solution]Pass correct and available Salesforce.com ids of files objects.

[errorMessage]"There is no wip files".
[Reason]If all of wipId in wipIds list is null or wipIds' size is 0.
[Solution]Pass wipIds with length greater than0 and non-null string values.

[errorMessage]" Insufficient Privileges. You do not have not access to update operation".
[Reason]If Object-level security for update access is not allowed.
[Solution] Make sure that update access is allowed for your profile.
Html upload example:

Code Block
<form>
File : <input type="file" name="file" id="file" />
      <input type="button" value="Upload" onclick="htmlUpload();"/>
</form>

<script type="text/javascript">

var uploadFile ;
document.getElementById('file').addEventListener('change', handleFileSelect,false);

function handleFileSelect(evt)
{
      var fileName = evt.currentTarget.files[0].name ;
      var fileSize = evt.currentTarget.files[0].size;
      uploadFile = evt.currentTarget.files[0];
      //Call initializeUpload() method
}
  
function htmlUpload()
{
      var fd = new FormData();
      fd.append('key', '{!uploadRequestInfosuploadRequestInfo.fileLocation}');
      fd.append('AWSAccessKeyIdacl', 'private');
      fd.append('x-amz-credential', '{!accessKeyuploadRequestInfo.awsCredential}');
      fd.append('aclx-amz-date', 'private{!uploadRequestInfo.timeStamp}');
      fd.append('policy', '{!uploadRequestInfosuploadRequestInfo.policy}');
      fd.append('signaturex-amz-algorithm', '{!uploadRequestInfos.signature}AWS4-HMAC-SHA256');
      fd.append('x-amz-server-side-encryption', 'AES256');   
      fd.append('Content-Disposition', 'attachment; filename=\"'+
    '{!uploadRequestInfosuploadRequestInfo.fileName}' +'\"');    
      fd.append('x-amz-signature', '{!uploadRequestInfo.signature}');   
      fd.append("file",uploadFile);
         
      var xhr = new XMLHttpRequest();
      xhr.addEventListener("load", htmlUploadComplete, false);
      xhr.addEventListener("error", htmlUploadFailed, false);
      xhr.open('POST', 'https://s3.amazonaws.com/'+’ + '{!bucketName}' + '. ', + '{!region}' + '.s3.amazonaws.com/', true);     // if region is us-east-1. leave region blank,    
     
      xhr.send(fd);    
} 


function htmlUploadComplete(evt) 
{      
        //Call completeUpload()  method   
}

function htmlUploadFailed(evt) 
{
        //Call cancelUpload() method      
}
</script>



You can see the appropriate values for the request parameters below (Figure 10).

Form Field

Value

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

'private'
SDriveTools.getAccessKey()
SDriveTools.getBucketName()
'attachment; filename=\"'+ uploadRequestInfos uploadRequestInfo.fileName+'\"'
uploadRequestInfosuploadRequestInfo.fileType
uploadRequestInfosuploadRequestInfo.fileLocation
uploadRequestInfosuploadRequestInfo.policy
uploadRequestInfos.signature
'AES256'
'AES256'
uploadRequestInfo.awsCredential
uploadRequestInfo.timeStamp
'AWS4-HMAC-SHA256’
uploadRequestInfo.signature
201