is it possible to download GMail attachment to local folder? - google-apps-script

i want to download attachment from gmail and save it to local folder using google script. i did some research about this and i could't find any solution.
so far, i managed to save gmail's attachment to google drive only.
var attachmentBlob = attachment[0].copyBlob();
var file = DriveApp.createFile(attachmentBlob);
folder.addFile(file);
or, is it possible to create a google script to auto download file from google drive?
need some advice.

As #Sujay already mentioned you cannot download a file to a local folder using Google AppScript because GAS runs server-side.
You have already taken a good step with the code to save the attachment as a file to your Google drive.
To answer your sub-question 'is it possible to create a google script to auto download file from google drive?', you do not need a script to do that, that is what the Google Drive Desktop App (https://www.google.com.ng/drive/download/) does exactly.
It syncs all the files you add to your drive to your local-pc. You can also edit Google Drive preferences to sync select folders only, in your case that might be the drive folder referenced in your folder variable.

GAS runs on the server side, and only has access to Google's internal architecture. To save locally it'll need to create some kind of a blob and trigger a download within your browser. not sure if you can do that.

Related

Allow Anyone to Upload Files Directly to my Google Drive

I would like to allow my students to send me one or more files directly to my google drive via a form where they would just enter their name and choose the file(s) to send (drag and drop would be great). A folder with their name would be created in a specific folder on my drive and a warning email would be sent to me. Do you think this is feasible with google script? Thanks in advance.
An example here but paying ...
I've checked and Google Forms already allows for a File Upload kind of question (with drag and drop too).
It automatically creates a folder in your Google Drive (altough it doesnt create a folder for every student) (example here) and in the spreadsheet that it automatically generates there is a permanent link to that file (example here).
If that's not what you are looking for and you need the 'Folder per student' feature then yes, you can use google apps script to move files in folders quite easily.

move generated google Form to specific google drive folder using google apps script

I am creating a few forms using Google Apps Script which automatically generates in my root (My Drive) of my Google Drive.
I want to move these forms to a specific folder of a Shared Drive.
I googled about moving files (or any object) to another folder, most of them are suggesting that copy the file to a specific location, then delete from the source location.
But in this case, my formIds are changing which I don't want to change.
Is there any better way to move files (in my case Forms) to another location in Google Drive?
As a developer you should always favor canonical sources over 3rd party tutorials that pop-up in google search. The official documentation for the Drive API has guides describing how to move files from one drive folder to the next. I suggest you start there.
the following code should work for moving any file, including forms, to a destination folder in Google Drive:
var fileId = '1234567890abcdefghijklmnopqrstuvwxyz'; //<--replace string with your file ID
var destinationFolderId = 'zyxwvutsrqponmlkjihgfedcba0987654321';//<--replace string with your destination folder ID
function moveFile(fileId,destinationFolderId) {
var destinationFolder = DriveApp.getFolderById(destinationFolderId);
DriveApp.getFileById(fileId).moveTo(destinationFolder);
}

Google Apps Script - Add file from Google Drive

First of all I want you to know that I'm not talking about uploading a file from users computer drive.
What Im aiming to do is to be able to allow users to add a file from their Google Drive to a specific folder in my Google Drive. I've searched around (a lot) and I can't find anything similar.
Have you ever seen this window? I could use something like it (it's in spanish but im sure you've seen it before). It allows you to upload a file from your pc or from your Google Drive:
Is it possible to access this pop up windows through Google Apps Script? If not, what are the alternatives?
What you have listed there is google picker. It can be used in apps script.
https://developers.google.com/apps-script/guides/dialogs#file-open_dialogs
The docs for Drive picker can be found at:
https://developers.google.com/picker/docs/
What you can do, is use the Drive Picker API to allow users to chose files from their google drive.
Then once you have the File, you can add it to your folder.
https://developers.google.com/apps-script/reference/drive/folder#addFile(File)
https://developers.google.com/picker/docs/

Google Apps Script to initate browser download when clicking on a Google Drive file

I have some particular files stored on my Google Drive with the extension of "bch". I need to be able to have a user click on this file in Google Drive and have it initiate the browser download prompt.
I was thinking that the way to do this would be to create a script that has the file information passed to it as a parameter and then execute the download request. I was hoping to define the file extension in the script so all files with this extension would be defaulted to run this script/app in Google Drive.
Has anyone done anything like this? If you could point me to some Google Apps Script examples I would greatly appreciate it. Thanks!

Upload file to Google Drive after downloading it from URL

Greetings! I am now writing a little script for my spreadsheet and I have the last piece of puzzle remaining unsolved.
I want to download a file (or get all the file data) from a specific URL and then upload it to Google Drive (or create a file with those file data). I believe I can do that but how? May anyone help me please?
If this doesn't work, then I would have to set up a server with my computer. Send a request from by spreadsheet script to my computer. Let my computer run a script and download the file and save it into a specific folder. Let Google Drive sync the file... This is totally possible but is there a simpler way to achieve what I want?
Thank you in advance!!!!!
In a nutshell:
var response = UrlFetchApp.fetch(url);
var file = DriveApp.createFile(response.getBlob()).setName(filename);
I've written a more complete script/webapp for this purpose. The full source-code is available at GitHub Gist and at Google Apps Script, feel free to study and use that code. There is also a live version.
Use UrlFetch Services to get the data from the URL and Drive Services to store this data on Google Drive