You need to sign in to do that
Don't have an account?
pavan.elthepu1.392651269495206E12
Failed to Load Attachment
Hi,
From Javascript, I'm trying to get attachment body and saving as attachment in Salesforce. But I'm getting Failed to load error on opening attachment. Here is my code:
Note: This code is working gret for txt files, but not for pdf files. Please help me
From Javascript, I'm trying to get attachment body and saving as attachment in Salesforce. But I'm getting Failed to load error on opening attachment. Here is my code:
jQuery.ajax({ type: "GET", url: "https://c.cs66.content.force.com/services/data/v39.0/sobjects/Attachment/00P0v000000IlLh/Body", beforeSend: function (xhr) { xhr.responseType = "arraybuffer"; xhr.setRequestHeader('Authorization', "OAuth " + session); //usually not needed but when you are //xhr.setRequestHeader('Content-Type', 'application/pdf'); xhr.setRequestHeader('Access-Control-Allow-Origin', '*'); xhr.setRequestHeader('Access-Control-Allow-Methods', 'GET'); }, success: function (data) { var att = new sforce.SObject("Attachment"); att.Name = "Pavan_JS.pdf"; att.ContentType = 'application/pdf'; att.Body = att.Body = (new sforce.Base64Binary(data)).toString(); //att.Body = window.btoa(data); - Works for txt file, but not for pdf files att.ParentId ="0030v000001cnSB"; var result = sforce.connection.create([att]); } });
Note: This code is working gret for txt files, but not for pdf files. Please help me