Instructions for transferring an email attachment to a collaborative drive stored in a Google Sheets document

At the moment, I am utilizing a Google script that runs periodically on my Gmail account to retrieve all attachments labeled according to certain criteria. The issue arises when trying to access attachments within a folder located on a shared drive using the getFolderByName method in Google Sheets.

After exploring various forum discussions, it became evident that leveraging the Drive API is essential for accessing folders on shared drives. Consequently, I aim to fetch the folder ID from my Google Sheet rather than relying on getFolderByName.

The following are three key functions:

  • getLibelleConfigs: Retrieves LibelleConfig objects from the configuration sheet
  • getFolderFromPath: Obtains or creates a folder based on its path
  • getOrCreateFolder: Retrieves an existing folder or creates a new one
function getLibelleConfigs() {
    // function code here
}
function getFolderFromPath(path) {
    // function code here
}
function getOrCreateFolder(folderName, parentFolder) {
    // function code here
}

Google Sheets excerpt:

+----------------+-----------+
|     LABEL      | ID FOLDER |
+----------------+-----------+
| example@email.com | xxxxx_1   |
| another@example.com | xxxxx_3   |
| test@test.com | xxxxx_1   |
| demo@demo.com | xxxxx_2   |
+----------------+-----------+

Edit

function saveAttachmentsFromLibelleConfig(libelleConfig, messageIdHistory) {
    // function code here
}

My Solution :

function movefileToSharedDrive() {
  // function code here
}

function makeCopy(srcFolderId, dstFolderId) {
  // function code here
}

function deleteFiles(folderId) {
  // function code here
}

The process involves triggering attachment extraction to my drive, copying to the shared drive, and deleting files from my drive to prevent duplicates.

Answer №1

To directly insert a file into a shared Drive, you can utilize the Drive.Files.Insert method from the Advanced Drive Service:

function saveToSharedDrive(sharedDriveId, fileBlob) {  
  const options ={
    supportsAllDrives: true
  }

  var resource = {
    title: fileBlob.getName(),
    mimeType: fileBlob.getContentType(),
    parents:[{
      "id": sharedDriveId
    }]
  }  
  Drive.Files.insert(resource, fileBlob, options)
}

Here, make sure to replace sharedDriveId with the ID extracted from your Sheet and fileBlob with a GmailAttachment object obtained as an array via:

GmailApp.getMessageById("message-id").getAttachments()

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Converting a JS string into HTML markup

I recently developed a basic web application to manage telnet connections with routers using Node.js, Express, and WebSockets. After establishing a connection, the terminal stream is transmitted through a websocket as UTF-8 strings. However, my current is ...

The issue of Three.js SkinnedMesh jittering arises when it is distant from the scene's root (0,0,0)

In my current project, I am developing a third-person RPG style game using Three.js and Blender. The terrain in the game world is tiled and loops endlessly in all directions, triggered when the player object approaches defined edges along the z or x-axis. ...

The elegant-admin template's mobile navigation toggle is missing

I recently downloaded an admin theme and added the CSS to my Django static files. However, after doing so, the mobile toggle feature disappeared. I double-checked all the CSS and JS links in the index template, and they are correctly linked to the paths, b ...

Maintain the initial value using ko.mapping.fromJS

How can I prevent new data fetched from an AJAX call using ko.mapping.fromJS from replacing the existing data in my observableArray? I want to append the new data without losing the previous entries. function ViewModel() { var self = this; self. ...

Autocomplete in Vue.js with cascading suggestions based on object keys

I have been experimenting with creating a 3 or 4 level cascading autocomplete feature in Vue.js, but I'm facing some issues with its functionality. You can view the original code on this CodePen link. <div id="app"> <v-app id=&qu ...

Ways to update a component from another in React

My React code includes an Employees page that renders both a Table component and a Filter component. The Filter component manipulates some data stored in the Employees page, updates the Filter's state through useEffect, and passes the data as a prop t ...

Adjusting the focal point of a brochure on open street map

I am currently working on initializing a map in an Angular application using leaflet with openstreetmaps. I have set the center of the map so that it is displayed to the user when they open the site. However, I am now trying to figure out how to dynamica ...

Can one manipulate SVG programmatically?

Looking to develop a unique conveyor belt animation that shifts items on the conveyer as you scroll down, then reverses when scrolling up. I discovered an example that's close to what I need, but instead of moving automatically, it should be triggered ...

Experiencing challenges with socket io connectivity between my backend and Quasar application. Encountering a 403 Forbidden error while trying to establish a connection with

I recently updated my Quasar app and ran into issues with the websocket connection after switching from development to production mode. The app is hosted on an Express server via pm2 on my Ubuntu server, which also connects to a database. Here are some sn ...

Another return payload failing to retrieve the return value

I'm currently facing an issue where a function that should return a value is not being passed on to another function. Below is the code snippet in question: public _getProfileToUpdate() { return { corporateId: this.storeService.setStoreData().p ...

I'm looking for a way to implement a jQuery-style initialization pattern using TypeScript - how can I

My library utilizes a jQuery-like initialization pattern, along with some specific requirements for the types it should accept and return: function JQueryInitializer ( selector /*: string | INSTANCE_OF_JQUERY*/ ) { if ( selector.__jquery ) return select ...

Revamp Label on Yii Update Button

I am in the process of integrating a like button into Yii. When I click on the button, it triggers a controller action that increments the number of likes by 1 and updates the Button label to display the new value. How can I achieve this? Here is my view ...

What is the best way to display data retrieved from a GET request in Angular?

Spending too much time on a development issue is causing me frustration. After extensive research, I find myself stuck at this point. The problem lies in making a GET request from a service which is called by a controller. Below is the code for the servi ...

Struggling to integrate Material UI (MUI) into my React application

I have followed all the necessary steps to install materialUI, emotion/react, and emotion/styled in my react app. However, I am encountering an issue where MUI does not seem to work properly. There are no errors displayed on the console or webpage, but not ...

Utilizing JQuery UI autocomplete for dynamically loaded textbox using AJAX

<div id='toolbox'> <div class='placeholder'></div> </div> In my project, I am using a click event to dynamically load a text box into the placeholder. $('#toolbox .placeholder').load('http:// ...

"Prisma vs. Supabase: A Comparison of Image Uploading

I am encountering an issue with adding image URLs to the Prisma database. I have successfully uploaded multiple images from an input file to Supabase storage, but when I try to add their URLs to the database, I receive an error regarding property compatibi ...

Connecting Mailchimp with WordPress without using a plugin can lead to a Bad Request 400 error when trying to

I'm attempting to connect with Mailchimp using an Ajax request without relying on a plugin, but I keep encountering a 400 bad request error. The code provided below utilizes vanilla JS for Ajax and the function required for integration with Mailchimp. ...

Sequential execution not functioning properly in NodeJS Async series

Here is the code snippet I am working with: var async = require('async'); var rest = require('restler'); async.series([ function(callback){ rest.get('https://api.twitter.com/1.1/statuses/mentions_timeli ...

Automatically scrolling down a div as new content is added using XMLHTTPRequest.openConnection

https://jsfiddle.net/kv5gbamg/ - I created a jsfiddle to demonstrate the functionality of the system Essentially, I am seeking a way to automatically scroll the scrollbar to the bottom every time a new message is received. My system updates the div with ...

ReactJS: Trouble encountered while parsing information from JSON data

Currently, I am facing an issue while trying to pass data from my JSON file to my ReactJS application. The error message that I am encountering is as follows: TypeError: Cannot read property 'mainPage' of undefined Upon console.logging siteDa ...