would appreciate if anyone can suggest ideas:
I currently have a Puppeteer script which automates CSV downloads into google drive which then allows me to programmatically access the data and move it into google sheets.
Currently, I run this locally on my computer on VS code. I don't yet understand all too well how to handle file downloads through puppeteer, but I currently have a work around by setting the default chrome download path to a folder on my computer, and that folder is actually Drive for desktop, so easy way to get files directly in drive.
await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: path.resolve('G:/My Drive/DriveData')});
Thing is, I'd like this to be some type of scheduled cloud function not having to be manually run on my computer. IF I were to do that, my Drive for Desktop work-around would not be viable. So is there a way I could pass the file download in Puppeteer directly into Google AppScript somehow? Or use the Drive API to directly receive the file?
My main issue is I don't understand how to actually handle file downloads in Puppeteer, I'm currently just editing the default download location for the google chrome instance puppeteer creates. I ultimately just need to get the data somewhere accessible by Google AppScript.
Any suggestions would be uber-appreciated!
I was also facing the same situation, unfortunately we cant install or use puppeteer in google app script environment,
The alternative is to do the file download using UrlFetchApp , cookies and sessions using session and cookies
The following code will help you save the file into Gdrive
var file = folder.createFile(UrlFetchApp.fetch("url of the downloaded file fetched dynamically"));
You need to check through the network logs in chrome to know how the file and on what URL request you are getting the file downloaded which you can pass to the function
Another alternative that will help you to download the file to drive is to use https://developers.google.com/drive
I had used python to save files in drive https://www.thepythoncode.com/article/using-google-drive--api-in-python
Related
I am currently exploring Google Drive APIs and am able to upload an individual file using Postman successfully.
I tried to create/upload a folder using Google Drive API but failed. In fact, I don't see any specific API to deal with a folder. I was giving it a try with create files API.
Reference - https://developers.google.com/drive/api/v3/reference
Any help will be appreciated.
If you check the documentation for files.create you will notice at the top it states
Creates a file.
This is singular each request creates a single file. If you want to upload a directory you will need to first create the directory then upload each file one at a time.
You could try batching but I don't think you can batch the file upload itself you could probably batch the metadata creation performance#details
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.
I am facing:Upload .XLSM file via the Drive API and then try downloading from the user drive interface. We have uploading an excel sheet to our newsprinter-sm drive with an .xlsm (macro) when we try to download google removes the .xlsm from the file name and the file is unusable unless you rename the file or select open with.
Google says:
They've checked the screenshot and can see that the code that the uploaded file itself removed the file extension, however, because of declared mime-type or file header, Google Drive recognized it as Excel-File. The behavior that the file you then download is subsequently not correctly recognized by your computer is expected: Your operating system seems to rely on file extension instead of mime-type or file headers and does not have a default file-handler for this type, however "open with" will open the untampered file.
In short: The file is downloaded in the same state as it was uploaded, no modification of content or filename was made by the API or Google Drive.
Please note that the scope of API Support team is to ensure overall API functionality. The API and Google Drive are behaving as expected.
Our team doesn't offer support for specific coding errors through this support portal.
Please let me know what to do on this.
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!
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