Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8854733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:57:05+00:00 2026-06-14T13:57:05+00:00

I have everything working except the actual file is not readable. I assume it

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:57:07+00:00Added an answer on June 14, 2026 at 1:57 pm

    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.

    var myFileId = 'MY_FILE_ID';
    var myParendId = 'ACCOUNT_ID';
    var myToken = 'USER_TOKEN';
    
    var baseContent = DocsList.getFileById(myFileId).getAs('application/pdf').getBytes();
    var base64Content = Utilities.base64Encode(baseContent);
    
    var payload =  Utilities.jsonStringify(
      {"Name" : 'ArunTest.pdf', //string
       "ParentId" : myParendId,  //string
       "body" : base64Content  //base64
      }
    );
    
    var options = {
            "method": "post",
            "contentType" : "application/json",
            "payload" : payload,
            "headers" : {
                         "Authorization" : "Bearer " + myToken
                        }
    }
    
    var getDataURL = UserProperties.getProperty(baseURLPropertyName) + '/services/data/v26.0/sobjects/Attachment/';
    var dataResponse = UrlFetchApp.fetch(getDataURL,options).getContentText();  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

everything is working fine with my jqgrid except a small issue. i have defined
I'm trying to create an RMA form and I have everything working except the
I am working on a weather app, and have everything working perfectly ...Except the
I am working on some form coding in PHP, and I have everything working
I have wrote a custom MultipleChoiceField. I have everything working ok but when I
I am currently implementing a ListView populated with CheckedTextViews and have everything working just
people. I have slight problem with GD2 text on image. I have everything working
I'm following the Django-CMS introductory tutorial and have got everything working up to the
I am working on a sample map kit app for iOS. I have everything
I have a IUSearchBar with an UISearchDisplayController, and everything is working well: When I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.