2

I am getting below problem when i try to upload a file on Google drive using save to drive button.

XMLHttpRequest cannot load https://ap1.salesforce.com/servlet/servlet.FileDownload?file=00P9000000jFRXN. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://c.ap1.visual.force.com' is therefore not allowed access.

How i can solve above problem using enable "CORS".

3

the issue can be addressed using the built-in HTTP(S) Proxy.

You can enable the proxy in the standard setup menu:

Setup -> Security Control -> Remote Sites / Remote Proxy Settings

Salesforce Setup Menu

There you can add your own salesforce instance. e.g. eu1.salesforce.com (don't forget to enable https)

In a second step you have to modify your ajax request:

var credential = ' OAuth ' + '{!GETSESSIONID()}'; // native VF function
var apiUrl = "https://na1.salesforce.com/services/data/v26.0/chatter/users/me";
$.ajax({
    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');
    }


});

Sources: https://trailhead.salesforce.com/modules/visualforce_fundamentals , https://gist.github.com/henriquez/3146782

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.