dowloading photos uploaded as google form answer with a name - google-drive-api

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.

Related

Intercept or get callbacks on Google Drive file save and open in addon/apps script

I want to build and AddOn for Google Drive that does extra pre-processing/decoration of files when they are uploaded and before opened/downloaded. E.g. add/verify digital signature, call 3rd party service passing file metadata, convert to different mime type, encrypt/decrypt certain files with custom key that's generated by 3rd party service.
I looked through all APIs and don't find any feature that allows to intercept file uploads/downloads and do pre-processing (e.g. intercept uploaded content, reading it as blob, do processing, then save it to Google Drive folder, later when user downloads file, do pre-processing/verification again on file contents and return end result) in a way that's transparent to user.
Another possibility in case intercepting the content would be to try intercept the file selection/upload event and change file extension or path to temp folder, then triggering processing script and saving result to original destination.
I prefer to avoid proxying file uploads/downloads via my custom backend, doing all required processing in context of addon/apps script.
I got a bit confused of how AppsScript GSUite Drive API (File, Folder, Drive classes) relates to Google Drive v2 API with Changes.watch(), Channels, etc...
Is latter intended for backend use only?
I can't see any notion of events/callbacks provided by AppsScript API, that in theory should be running my addon in context of current user.
I wish I would be abler to ask more concrete question here on API, but currently I struggling to understand how to do basic hooks for my addon to operate on files.
You can't intercept them. With a Drive Add-on you can only trigger functions when the user enters Drive's homepage or when the user select a file(s). With the API you can watch when a file is modified in order to get a notification, but this will be after the change is made without intercepting the change process.
If you use a OnItemsSelectedTrigger, you need to prompt/return a Card when the user selects a file(s), in this card you can set buttons that when clicked by the user it can trigger different actions.

Adding the captions via the google drive sdk

I have 1k+ closed captions (in the srt format) and I would like to add all of them to my videos on the google drive. Is it possible to do it via the API?
thank you
Radek
Yes, it is possible through Drive REST API. See Upload Files. You have three choices for this, Simple upload, Multipart upload and Resumable upload.
Simple upload
The most straightforward method for uploading a file is by making a simple upload request. This option is a good choice when:
The file is small enough to upload again in its entirety if the connection fails.
There is no metadata to send. This might be true if you plan to send metadata for this resource in a separate request, or if no metadata is supported or available.
Multipart upload
If you have metadata that you want to send along with the data to upload, you can make a single multipart/related request. This is a good choice if the data you are sending is small enough to upload again in its entirety if the connection fails.
Resumable upload
To upload data files more reliably, you can use the resumable upload protocol. This protocol allows you to resume an upload operation after a communication failure has interrupted the flow of data. It is especially useful if you are transferring large files and the likelihood of a network interruption or some other transmission failure is high, for example, when uploading from a mobile client app. It can also reduce your bandwidth usage in the event of network failures because you don't have to restart large file uploads from the beginning.
You may also want to see Work with Folders for inserting files in a folder.

Google Drive API: Getting properties for a large number of files

I have an application which manages file metadata on Google Drive, and naturally stores it as properties on the files. Since this application needs the metadata for all files when loading, I end up making hundreds of requests of Properties: list
https://developers.google.com/drive/v2/reference/properties/list
- one of these for each file my app manages.
Is there a way to get the properties in bulk for all files in a folder?
Files: list supports adding the field items/properties to its fields parameter, so clearly the thought occured to someone that this should be possible, but that field is never populated. Am I doing something wrong or is this just not an option?

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.

How i can get multiple files from google drive through the 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.