You need to sign in to do that
Don't have an account?
Downloading Content Document in Salesforce
Hi i was trying to download the attachment for content document which is text file.. I used the url https://c.ap1.content.force.com/sfc/servlet.shepherd/version/download/06890000000CZjT
and while downloading, the below content is present in downloaded text file instead of its actual content. I think this occurs if i m not authorized to access the content. But i specified http headers for authorization and Content-disposition. But i could not download the actual file. Any pointers or any other way to download the salesforce content document is really helpful
Thanks,
Vamsi.
<script>
if (window.location.replace){
window.location.replace('https://login.salesforce.com/?ec=302&startURL=%2Fcontent%2Fsession%3Furl%3Dhttps%253A%252F%252Fc.ap1.content.force.com%252Fsfc%252Fservlet.shepherd%252Fversion%252Fdownload%252F06890000000CZjT');
} else {;
window.location.href ='https://login.salesforce.com/?ec=302&startURL=%2Fcontent%2Fsession%3Furl%3Dhttps%253A%252F%252Fc.ap1.content.force.com%252Fsfc%252Fservlet.shepherd%252Fversion%252Fdownload%252F06890000000CZjT';
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
</head>
</html>
<!--
...................................................................................................
...................................................................................................
...................................................................................................
...................................................................................................
-->
MY CODE:
function downloadFile(){
console.log("> downloadFile--");
window.requestFileSystem(
LocalFileSystem.PERSISTENT, 0,
function onFileSystemSuccess(fileSystem) {
fileSystem.root.getFile(
"dummy.html", {create: true, exclusive: false},
function gotFileEntry(fileEntry){
var sPath = fileEntry.fullPath.replace("dummy.html","");
var fileTransfer = new FileTransfer();
fileEntry.remove();
fileTransfer.download(
//"http://www.w3.org/2011/web-apps-ws/papers/Nitobi.pdf",
"https://c.ap1.content.force.com/sfc/servlet.shepherd/version/download/06890000000CZjT",
sPath + "DNotesOAuth.txt",
function(theFile) {
console.log("download complete: " + theFile.toURI());
showLink(theFile.toURI());
},
/*
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code: " + error.code);
}
*/
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
},
false,
{
headers: {
//"ACCEPT": "text/plain"
//"Content-Type": "application/octetstream"
"Authorization" : "OAuth 00D90000000n5Zf!AQoAQC05DDFvKVRz1fuaQ_DmjSxePcWD2zm9JICR3xBKO9H25GqGJbrya9.MFbsG8KvVRYb9Y9j85nigb23A7YsZVbePeXoi",
//"Accept": "application/octetstream"
"Content-disposition": "attachment"
}
}