Is it possible to upload an entire folder to Google Drive using Google Drive API? - google-drive-api

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

Related

Why can't i transfer ownership of google drive folder and files to other? (OwnershipTransfer libary is being used)

The library I am using is from here.
The response has very little info to debug or I don't understand what is this. It supposed to be easy from what I read in the description.
Any help?
That's an intended behavior. From your screenshot, I'm assuming you're using a G Suite/Workspace account for your 5times.co.in email. Please take note that transferring files from one Workspace account to another workspace account or Gmail is not possible as of the moment.
This is a documented here: https://support.google.com/a/users/answer/9308960
You can transfer ownership of your Google Drive files and folders to someone else in your organization.
an alternative is to either use Shared Drive or download the file and re-upload it to your Gmail account.
A better way to do this is:
step-1: Transfer files from the drive (your Gdrive) to google cloud storage
step-2: Transfer files from google cloud storage to drive (new Gdrive, different organization)
Reference python code for file transfer between DRIVE & Google drive.
https://colab.research.google.com/drive/1Xc8E8mKC4MBvQ6Sw6akd_X5Z1cmHSNca

How I can read the contents of text file using google drive api v3

I tried to use Get(). I was able to read/update the file metadata but don't know how to get the file contents. From my googling I know I have to identify alt=media but I don't know how. Could anybody give a full example.
To retrieve the contents of a Gogle document like Google Sheets, Google Docs etc. you can use the Sheets API, Docs API etc. respectively
To retrieve the contents of a non-Google file on your Google Drive, like e.g. a text file - you cannot do it directly
Instead, you need to donwload the file to your local Drive
For this, when using the method Files: get, specify alt=media as you already know
However, this will not directly give you the file contents, but rather request a download of the contents from the server
In the next step you need to write this downloaded content to a file on your local machine
The Guide for downloading files stored on Google Drive provide samples of how to do so in Java, Python and Node.js

is it possible to download GMail attachment to local folder?

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.

Move file from appDataFolder to user's root folder with Google drive API

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.

google drive folder information

I would like to use Google Drive to push files in various folders onto a remote computer. I would like this to be a one-way transaction so the people using the computer cannot write to Google Drive.
However, when I use the following C# code to get the files from Google Docs I only get the file names, not their directories where they will be on the remote computer. This won't work because some files in different directories have the same name. Is there a way to programmatically get directory information from these files?
Alternately, if I could set up the Google Drive folder to be read-only, that would accomplish my goal and probably be easier. Can this be done?
You should use the Google Drive API to list all files and check the parents field of each of them to map those files into folders:
https://developers.google.com/drive/v2/reference/files#resource