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.
Related
TLDR: Google Drive does not index markdown files or mime type text/markdown by default. I'm looking for a way to make sure that all files in a specified directory are being indexed by Google Drive.
I have applications on Windows desktop and Android mobile such as Obsidian and Markor that saves markdown document files (.md) to a Google Drive folder with a mime type of text/markdown.
When I attempt to search for terms in the content of the markdown files from the Google Drive website, they do not appear to have been indexed and cannot be found. I can only find terms in the filename of the markdown files.
I can create a text document (.txt) with the same content as the markdown file and they are saved to Google Drive with a mime type of text/plain. The content of these text files are indexed and can be found using search on the Google Drive website.
I came across the following article indicating that there is a way via the Google Drive API/SDK to mark a special Google Drive attribute called indexableText to 'true' for mime types that are not indexed by default by Google Drive.
https://gsuite-developers.googleblog.com/2013/02/how-to-make-files-searchable-in-google.html
It states, "We recently added a way for you to indicate that the file you are uploading is using a readable text format,".
The excerpt indicates that this method is meant to be used as the files are being uploaded.
My question is whether it's possible to set the indexableText attribute to 'true' on existing files or after the files have already been uploaded?
My goal is to have a script that is either triggered by the creation of a new file or that runs at regularly scheduled intervals to make sure that all files in a specified directory are being indexed by Google Drive.
If there are already apps, scripts or services that provide this functionality, I would welcome your recommendations.
I noticed this behavior on Google Drive.
When a link is created for a file on Google Drive, the link is valid until the file is deleted.
Moving the file to another folder(s) does not affect the behavior of url.
I will like to understand how they achieved this at scale.
This is an expected behavior when moving files to another folder within your google drive. This is because a google file URL is usually composed of the following:
product domain
product
document Id
Therefore, moving the file to another folder within the google drive will not affect the file URL because file path is not included in the URL format.
References:
Google Sheets API Overview
Docs API
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
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.
Is it possible to move file from appDataFolder to user's root folder on Google Drive using drive API v2 or v3? I can't find any example how to do that. I just try to use gapi.client.drive.files.update from javascript drive v3 API and addParents parameter to change folder, it works fine with files in user's root folder, but doesn't work with files in appDataFolder.
I know that it is possible to copy file from appDataFolder to user's drive root, but I need to keep fileId, and copying generates new fileId for copied file.
I found there is a file property called "spaces" and files from appDataFolder a in spaces=appDataFolder whereas files from user's root folder are in spaces=drive. Is it possible to move file between these spaces keeping same fileId?
I found some similar posts:
Copy an exising Drive file into the appdata folder
Is it possible to share the application data on google drive
and it looks like it is not possible to do it this way. When I check my console I also get "Method not supported for appdata contents" or "Method not supported for files within the Application Data folder." message.
So is there any method to move file from appDataFolder?
Thank's for help.
No, it seems to be impossible. The current document doesn't mention about that, but the error message clearly says so. Thumb down for drive api.