Im trying to write a script that will grab a series of attachments and zip them up using JSZip. All is working well but the script does a call to grab the download url

it seems like whats happening is this:


is redirecting to this


and since posse--devbox--c.cs9.content.force.com and posse.my.salesforce.com are different domains i cant access the file because of CORS issues?

here is the full error

XMLHttpRequest cannot load https://posse--devbox--c.cs9.content.force.com/servlet/servlet.FileDownload?file=00PK0000001OAPR.

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://posse--devbox.cs9.my.salesforce.com' is therefore not allowed access.

Any ideas would be really helpful

1 Answer 1


You will have to channel through the VF proxy to resolve this error



The above gist should help and I have reproduced the content below so that helps even when link is broken .Replace with necessary URL and should help

<apex:page controller="CustomerCommunityController" id="customercommunitycontroller" sidebar="false" showHeader="false" standardStylesheets="false" >
    <title>Acme Customer Support</title>
      <meta charset="utf-8" />     
     <apex:includeScript value="{!$Resource.jquery}"/>          

 <script type="text/javascript">

 /* Same Origin Policy limits javascript running in VisualForce pages from making requests to 
    APIs, even salesforce apis, because they are hosted on salesforce.com while visualforce 
 pages are served from force.com.  To work around this, configure an ajax proxy in your organization.
 Ajax proxies are configured in setup under Security Controls | Remote Site Settings. Put in a URL    
 into the proxy like https://na1.salesforce.com (or whatever the domain of the api is)

 Once configured, just plain javascript can use the proxy url, which is available at /services/proxy
 The Salesforce Ajax Toolkit is not required, and generally you don't want to use that anyway, since
 its not supported on Safari or Chrome.

 Here's a basic example of how to make a request to the Chatter REST API from a Visualforce page.    
    This also works for portal(community) users and portal pages.

  (function() {
    var $;

      $ = jQuery;

      $(function() {
       var credential = ' OAuth ' + '{!GETSESSIONID()}'; // native VF function
       var apiUrl = "https://na1.salesforce.com/services/data/v26.0/chatter/users/me";
        type: "GET",
        // for community pages, use whole community url including path, e.g. 
        // https://logan.blitz01.t.force.com/customers/services/proxy.
        url: "https://c.na1.visual.force.com/services/proxy", 
        contentType: 'application/json',
        cache: false,
        success : function(response) {
                      alert("result" + response);
        error : function(response) {
                      alert("Failed" + response);
        dataType: "json",
        beforeSend: function(xhr) {
            xhr.setRequestHeader('SalesforceProxy-Endpoint', apiUrl);
            xhr.setRequestHeader("Authorization", credential);
            xhr.setRequestHeader('X-User-Agent', 'MyClient');



 This is your new Page


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .