I have everything working except the actual file is not readable. I assume it loads since I dont get any errors and the attachment is created. The “file” needs to be base64 in salesforce so I am assuming my problem is that the blob in Drive is not base64. The question is, how do I convert the file blob to a base64 format for uploading, and will this actually work.
Relevant Code chunks
var payload = Utilities.jsonStringify(
{"Name" : name, //string
"ParentId" : acctId, //string
"OwnerId" : ownerId, //string
"body" : content //base64
}
);
var contentType = "application/json; charset=utf-8";
var feedUrl = instanceUrl + "/services/data/v23.0/sobjects/Attachment/"
var response = UrlFetchApp.fetch(feedUrl, { method : "POST", headers : { "Authorization" : "OAuth " + accessToken }, payload : payload, contentType: contentType });
var feed = JSON.parse(response.getContentText());
looking at it here it seams the Utilities.jsonStringify() the file would be an issue. Still need some help making this work though.
The code snippet below works for me. I re-wrote it a bit to fit my sample. I didn’t include an ownerid as I didn’t know what to include there. I think the key issue might be that you didn’t use
getAs(). If you got pure Google Doc blob then your browser won’t know how to convert that. Notice, how I used application/pdf. I believe you can use a similar MIME type for MS Word as well. Also note that I converted to Base64 using the Utilities API.