I have been trying to upload file from Visualforce using the blog tutorial on developerforce that explains CORS feature.I am preferring REST API tied with VF since I need to built lot of other client side actions based on response like progress bar and other cool features
I used exact same code with forceTk imported in my VF
<apex:page docType="html-5.0" title="File Uploader">
<h3>Select a file to upload as a new Chatter File.</h3>
<input type="file" id="file" onchange="upload()"/>
<p id="message"></p>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="{!$Resource.forcetk}"></script>
<script>
var client = new forcetk.Client();
// Get the token from Visualforce
client.setSessionToken('{!$Api.Session_ID}');
function upload() {
var file = $("#file")[0].files[0];
client.createBlob('ContentVersion', {
Origin: 'H', // 'H' for Chatter File, 'C' for Content Document
PathOnClient: file.name
}, file.name, 'VersionData', file, function(response){
console.log(response);
$("#message").html("Chatter File created: <a target=\"_blank\" href=\"/" +
response.id + "\">Take a look!</a>");
}, function(request, status, response){
$("#message").html("Error: " + status);
});
}
</script>
</apex:page>
trying for few hours now I get below error in the javascript console only for firefox browser .Worked well in chrome
It worked well in chrome but chrome also throws an error but still file upload succeeds while in mozilla it fails .
In chrome the error message is as below
Any help will be appreciated