2

first time i am using AWS and s3 i have to integrate it with salesforce for uploading large files when i try to upload a file it is giving me error

OPTIONS https://s3.amazonaws.com/ritesh 403 (Forbidden) resumable.js:344
XMLHttpRequest cannot load https://s3.amazonaws.com/ritesh. Origin https://c.ap1.visual.force.com is not allowed by Access-Control-Allow-Origin.

i am using resumable.js(a javascript library for sending big files in chunk) as you can see i am sending file from url https://c.ap1.visual.force.com then i tried to send it

the code segment from where i am sending file is

var r = new Resumable({
            target:'https://s3.amazonaws.com/ritesh',
            chunkSize:1*1024*1024,
            simultaneousUploads:4,
            testChunks:false,
            throttleProgressCallbacks:1,
            query:{ 'key': 'Hello10'  ,'AWSAccessKeyId': '*********' ,'policy':'{!$RemoteAction.S3FormController.getPolicy1}' ,'signature':'{!$RemoteAction.S3FormController.getSignedPolicy1}', 'acl': '{!AWS_S3_Object__c.Access__c}','success_action_status':'201' , 'success_action_redirect':'https://'+'{!$RemoteAction.S3FormController.getServerURL1}'+'/'+'{!AWS_S3_Object__c.id}' ,'Content-Type' :'application/zip'   }



          });

because i am using an existing JS library thats why its looking little weired.this code means i am sending a post request to https://s3.amazonaws.com/ritesh ritesh is my bucket name setting other post parameters like key ,AWSAccessKeyId,policy,signature,acl,success_action_status etc all parameters are praobably correct why i am getting this error.my Cors Configuration is

<CORSConfiguration>
 <CORSRule>
   <AllowedOrigin>https://c.ap1.visual.force.com/</AllowedOrigin>

   <AllowedMethod>PUT</AllowedMethod>
   <AllowedMethod>POST</AllowedMethod>
   <AllowedMethod>DELETE</AllowedMethod>

   <AllowedHeader>*</AllowedHeader>
 </CORSRule>
 <CORSRule>
   <AllowedOrigin>*</AllowedOrigin>
   <AllowedMethod>GET</AllowedMethod>
 </CORSRule>
</CORSConfiguration>

i am sending only parameters not any header should i have to send additional headers which headers please menton!!please please help how to remove this error

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
mathlearner
  • 7,509
  • 31
  • 126
  • 189
  • If an external system needs authentication then you need to have authorization in header...One thing i would suggest is to look at amazon api developer guide and find out how you Will use header – Mohith Shrivastava Feb 10 '13 at 19:27

1 Answers1

0

You have to use the SFDC HTTP proxy. For this you have to define the address https://s3.amazonaws.com as "Remote Site" -> Setup -> Sec. -> Remote Sites.

Enter the URL for the remote site. All s-controls, JavaScript OnClick commands in custom buttons, Apex, and AJAX proxy calls can access this Web address from salesforce.com.

Your new request should use the endpoint url: "https://c.[Instance].visual.force.com/services/proxy".

In the header of your request you have to add 'Authorization': 'OAuth {!GETSESSIONID()}' and your api-endpoint-url 'SalesforceProxy-Endpoint', apiUrl