skip to Main Content

I am trying to upload a file to S3 using apps script.

I have been trying to use https://github.com/viuinsight/google-apps-script-for-aws

S3.init();
S3.putObject("bucket123", 'Tacofile.txt', content, 'ca-central-1')
  1. I retrieve a file from Google Workspace, where ‘Tacofile’ is a .txt file
  2. The file successfully loads to S3

The file, however, somehow gets converted to json? How to keep the file as a csv or is there a way to specify the MIME type somewhere before the upload?

thanks in advance

CB

2

Answers


  1. Chosen as BEST ANSWER

    @theWizEd thanks for pointing me in the right direction! I think I got this to work. I changed my source data so my download was done using:

    object = DriveApp.getFileById(file_id).getBlob().getDataAsString();
    

    i changed the section in line 106 below:

      if (notBlob) {
        object = Utilities.newBlob(JSON.stringify(object), "application/json");
        object.setName(objectName);
      }
    var content = object.getDataAsString();  
    var contentType = object.getContentType();
    var contentMD5 = getContentMD5(content);
    

    to the following

      if (notBlob) {
        //object = Utilities.newBlob(JSON.stringify(object), "application/json");
        //object.setName(objectName);
      }
    
      var content = object; 
      var contentType = MimeType.PLAIN_TEXT
      var contentMD5 = getContentMD5(content);
    

  2. Yes use File.getBlob() S3.putObject("bucket123", 'Tacofile.txt', content.getBlob(), 'ca-central-1')

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search