how to upload a file in googleDrive non-root folders using APIs? - google-drive-api

I can upload files in root folder of Google-drive using Google-drive APIs. But I cannot upload files to non-root folders. Is it possible to upload a file in non-root folders using APIs?and DO we have any other APIs for uploading a file in non-root folders.
I am using "https://www.googleapis.com/upload/drive/v3/files" Url and I am trying to append file-Id to this Url, but I failed to upload the file to a sub-folder.

I suggest start by reading this post How do I search sub-folders and sub-sub-folders in Google Drive?. Even though the question is about searching, you will find the answer will help you to understand Drive folders. Once you realise that a Folder is really just a label, the answer will be obvious.
In simple terms, your file metadata must contain an array called "parents" (https://developers.google.com/drive/v3/reference/files#resource-representations). Simply populate that array with the file IDs of the folders you want the new file to be created in.

Related

Is it possible to upload an entire folder to Google Drive using 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

How to download shared file from Google Drive using a link?

For example we have a link to Google Drive: https://drive.google.com/file/d/1o4bqvKsGjf_yukzt-zQPtZWtqv21gpmv/view?usp=sharing
This file on someone's drive, not on my own. And how to download this file using API, if I know only a link?
The share with me link that you can get via the google drive web application. is not a true form of sharing.
In order to download a file using the api you must first have permission to access that file. That being said you must have a record on the file with your username (email address) returned by a premissions.list call on the file.
Without it when you do a file.list the file will not show up as you do not have permissions on the file.
The issue with the share with me link is that the Id is not the id of the file. So even if the file was public you would not be able to find it.
To be clear a share with me link to a file on google drive does
not contain the true file id needed for the api
grant any true permissions on the file. meaning that you cant access it via the api.

How does google Drive fetch all containing files of folder while we upload folder?

I noticed that while upload any folder on Google drive, Its automatically listed all containing files from an specific folder, however its all at client end and as per my knowledge no any client end language access client directory or system details then how Google Drive listed all containing files by giving only folder reference.
I am not sure about the exact implementation for Google Drive folder upload, but in HTML5, there is a webkitdirectory which support the operation.
See: http://earlysandwich.com/programming/how-to-upload-multiple-files-or-folders-with-html-and-php-168

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