How i can get multiple files from google drive through the google drive api? - google-drive-api

I would like to know how i could to obtain multiple files from google drive. I searched this in the reference but i not found this information. I'm building a web application that will talk to drive and retreive a link of a zip file to download. Zip of the files.
I'm using php with api v2.

That is currently not possible with the Drive API, you have to send multiple requests to retrieve multiple files.

I've been faced with a similar problem and while there's currently no way of doing this through Drive (to my knowledge), this is the solution I came up with.
I'm serving up hundreds of thousands of files to clients using a Drive folder as the storage with a custom built front-end built with the Drive API. With that many files, it's ridiculously tedious for users to download files one at a time. So the idea was to let the users select which files they'd like to download and then present them with a zip file containing the files.
To do that, first you'll need to get an array of the Drive files that you want to download whether that's some you generate programmatically or through check-boxes on the front-end. Then you'll loop through that array and grab the 'downloadURL' value for each file and perform a cURL to the url provided. Depending on how many files you're planning on handling per request you can either keep them all in memory or temporarily store them on the disk or in a database. Regardless, once you have all of the files, you can then zip them up using any number of zip libs that are out there. Then just send the resulting zip file to the user.
In our case we ended up sticking with individual file downloads because of the potentially massive amount of resources and bandwidth this can eat but it's a potential solution if you're not serving large numbers of files.

Assuming I am answering the correct query, if you place the files in a folder on google drive, then as far as I know it is possible to download as a complete group of files.

Related

dowloading photos uploaded as google form answer with a name

I have created a google form where I collect info about workers (name famil photo etc...).
I want to download all photos uploaded through the form to my PC but I want each photo downloaded to have a name suitable to the name and family answers that the worker submitted , i.e. _.
This will be used to produce magnetic cards automatically without the need to go over each one and choose his image manually.
For uploading file, you can use the method specified in the documentation.
The Drive API allows you to upload file data when creating or
updating a File resource.
You can send upload requests in any of the following ways:
Simple upload: uploadType=media. For quick transfer of a small file (5 MB or less). To perform a simple upload, refer to
Performing a Simple Upload.
Multipart upload: uploadType=multipart. For quick transfer of a small file (5 MB or less) and metadata describing the file, all in
a single request. To perform a multipart upload, refer to
Performing a Multipart Upload.
Resumable upload: uploadType=resumable. For more reliable transfer, especially important with large files. Resumable uploads are a good
choice for most applications, since they also work for small files at
the cost of one additional HTTP request per upload. To perform a
resumable upload, refer to Performing a Resumable Upload.
Most Google API client libraries implement at least one of the
methods. Refer to the client library documentation for additional
details on how to use each of the methods.
Then you can manipulate your metadata,
Much of the information you'll need to get started inserting and
retrieving files is detailed in the Files reference. Here are a
few more important considerations for naming files and working with
metadata like thumbnails and indexable text.
Next, here is how to Specify file names and extensions
Apps should specify a file extension in the title property when
inserting files with the API. For example, an operation to insert a
JPEG file should specify something like "name": "cat.jpg" in the
metadata.
Subsequent GET requests include the read-only fileExtension
property populated with the extension originally specified in the name
property. When a Google Drive user requests to download a file, or
when the file is downloaded through the sync client, Drive builds a
full filename (with extension) based on the title. In cases where the
extension is missing, Google Drive attempts to determine the extension
based on the file's MIME type.

Get file list from google drive public folder shared by link via API

I'm trying to create script to download all files from another user shared folder in google drive using rest api. If i'm right, there are two variants:
Using drive.children.list, with folder ID
Using drive.files.list, with search query like 'FOLDER_ID in parents'
But both of this variants returning only files which were once opened by my google account in browser. If I open file in browser - this file will appear in results of API calls.
Folder is shared for anyone, who has link.
Where is the problem, how I can list all files in folder?
Since you did not give us any info about the SCOPE, I am wild-guessing that it may be your problem. You probably have FILE scope, instead of DRIVE.
Also, I would recommend to test these things with 'TryIt!' here. You can quickly modify both scopes and queries there.
Good Luck
This is a bug/quirk in the Drive API, though there is an easy workaround. If you call files.update with 'addParents=root' it'll add the shared folder under 'My Drive'. This has the effect of making the files part of your corpus and they'll appear in results.

File name conversion for cloud storages?

Lets say I have a web URL to a file on a cloud storage (like Dropbox, Google Drive, etc). How do I convert that to the corresponding file path on my pc? On Android? On iOS?
Assuming of course I have the utilities/apps installed locally.
EDIT: I interested in file name the reverse direction too. (I.e. when I have the local file path, what is the web path?)
EDIT 2: #Greg just made me realize that the problem with file name is much worse on Google Drive than on Dropbox.
And that is very bad. :-(
The reason? Google has good search capabilities on Drive and therefor I and many, many others have put their documents on Drive. However, once I found it I must locate it on my on computer/device. (If I want to edit a pdf for example.)
EDIT 3: #Dan McGrath kindly asked what parts remain unsolved.
Short answer: All. ;-)
Long answer: My actual use case, see below.
My actual use case is a Zotero web app. Zotero is a reference database where you store references to scientific articles, web pages, etc. The items stored in Zotero may include PDF files or - which I prefer - links to PDF files.
I just want to be able to easy access (read) this PDF files from any computer through the web app. And on my own computer I want to be able to edit the files with my local PDF editor. (Be it Android, Windows or whatever.)
By using a cloud storage I do not have to download/upload the files myself. The cloud storage takes care of that part.
For the "reverse" scenario, that is, you have a file and you want the Dropbox shared link, you can use this API endpoint, assuming you're connected to the account via the API:
https://www.dropbox.com/developers/core/docs#shares

How to get an accurate file list through the google drive api

I'm developing an application using the Google drive api (java version). The application saves files on a Google drive mimicking a file system (i.e. has a folder tree). I started by using the files.list() method to retrieve all the existing files on the Google drive but the response got slower as the number of files increased (after a couple of hundred).
The java Google API hardcodes the response timeout to 20 seconds. I changed the code to load one folder at a time recursively instead (using files.list().setQ("'folderId' in parents) ). This method beats the timeout problem but it consistently misses about 2% of the files in my folders (the same files are missing each time). I can see those files through the Google drive web browser interface and even through the Google drive API if I search the file name directly files.list().setQ("title='filename'").
I'm assuming that the "in parents" search uses some inexact indexing which may only be updated periodically. I need a file listing that's more robust and accurate.
Any ideas?
could you utilize the Page mechanism to do multiple times of queries and each query just asks for a small mount of result ?

Copy a file from Google Drive to my own server

If you remember, I'm trying to integrate Google Drive within our website, which is built on Elgg. Elgg already has its native file management system.
What we would like to do is to copy a file from Drive to our server, you know, kind of : Send to My Files. The problem is that I don't see any URL in the file metadata indicating where the file is physically stored.
I can see the copy function in Google Drive SDK but I don't think it allows to copy the file on our own server. Unless I've read it wrong.
Can you help me?
Thanks you.
If you are trying to save a file that has content stored in drive (e.g an image, pdf, etc.), the file's metadata should contain a downloadUrl that can be used to retrieve the file's content through an authorized GET request.
For Google Documents (Google Docs, Google Spreadsheets, etc.), the data is stored in a private format that cannot be understand by third party applications. In this case, your app will have to use one of the exposed exportLinks to export the document into a format understood by your application.