How to fetch the URL of an uploaded IMAGE or VIDEO from a GOOGLE FORM using GOOGLE APP SCRIPT? - google-apps-script

I'm trying to create a google app script function where I want to fetch the URL of the image/video uploaded in the google form so that I can use it to display in my google web app. I'm not able to find any solution.
In the image below, the page source shows the URL of the image that was uploaded in the form. This URL is what I want from the app script.

When a file is uploaded via a Google Form, the file is placed in a folder within the form owner's Google Drive.
If you are the form owner, a new folder will be created within your drive and you will be able to access them using the Google Drive API.
Check out the documentation here: https://developers.google.com/drive/api/v3/search-files
If you know the name of the form, you can search the Folder within your drive and then use the API list the files within that folder using files.list .
You can find the fields within Files here: https://developers.google.com/drive/api/v3/reference/files and can use these fields to any specific URLs.

Related

How to link to a Google drive file? [duplicate]

Using the Google Drive API I can get a file's webViewLink to link to the file-preview in Drive, and the user can then select 'Open with Google Sheets' in the top bar to open the file up in Sheets.
Is there a way to skip that intermediary step, and link directly to that file in Google Sheets?
File.resource also contains a link called webViewLink
webViewLink string A link for opening the file in a relevant Google editor or viewer in a browser.
This will not work on all file types but it should work on sheets.
What are you seeing in webViewLink?
When I try, I get
"webViewLink": https://docs.google.com/spreadsheets/d/1egZQnArX7TOHlQWSHiba3TTNt9Y7JoqgDAIJMdM0MQ/edit?usp=drivesdk"
which directly opens the sheet.
So a couple of things:-
Are you sure that the file in question is a native Google spreadsheet, or is it, for example, an uploaded Excel
If your webViewLink is different, you could construct the URL yourself by setting your own file's ID after the /d/

Google Drive Url System Design

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

Rename files in Google Drive that have been collected through Google Forms

I am collecting Friends photos through a Google Form. The Form has only two fields Name (text) and Photo (upload).
The uploaded photo is stored in a folder in Google Drive and a hyperlink appears in the Google sheet to the name.
The issue I am facing is that the photo stored in Google Drive usually has a name generated while taking the photo and is not the name of the person whose photo it is. I want the photo file name to be the same as the person's name.
I don't know much of Google Scripts and would like help in using a script to rename the files in the Google Drive with the name of the uploader which is in the Google Sheet.
To rename uploaded files in Google Drive that have been collected through Google Forms you can
create your own apps script that will process all files received via Google Form, as described here or here, or
use my Google Forms add-on Form Uploads Manager that renames the uploaded files, move them to the Google Drive folders you specified and can add a description for each uploaded file, which makes it easy to find files using the built-in Google Drive search. A detailed description of the add-on settings is available on the app home page.
Disclaimer: This is my Google Forms add-on, which I created for my own purposes, and after successful use I posted it on the Google Workspace Marketplace. After a 1 week trial (which might be enough to reach your goals), a paid add-on subscription is required.

Flutter URL to create and open a new google drive folder

I'm wondering is there a URL I can run that will create a new Google Drive folder and then open it in the Google Drive app (on phone or tablet).
I know you can create the folder via the google drive API, but not open the Google Drive app it seems.
I'm looking for something like the Google Maps URL where you specify e.g. destination coordinates in the URL and it opens with the route to those coordinates.
Many thanks for any help with this.
I'm afraid that creating a folder that way is not possible. You can however, do it through the API. The flow would be as follows:
Your application requests the user's authorization.
The user logs in to his Google account and accepts.
Your application creates a folder in his Google Drive instance.
Your application retrieves the link of the newly created folder.
Your application opens the URL. In case the user has the "Google Drive" application, and he has not set Google Drive links to open with another app by default, it will be open with the app.
You can read more about how to create a Drive Folder using the Google Drive API for Dart here:
Dart GoogleAPIs Package: Library to use several Google APIs.
Files create endpoint: Endpoint to call to create a folder. To create it, you will have to set the "mimeType" in the request body to: application/vnd.google-apps.folder

Google Apps Script - publish google documents and read urls

I'm new to Google apps script.
I can create a number of documents in Google Drive via a script and add content.
I would also like to publish them via a script and record the published URL. Is this possible?
I can see an old answer from 2012
"Publish to the web" for Document in Google Apps Script?
You can create all your content in a publicly shared folder, then once you have the folder's ID, you can create a straightforward base URL (e.g. https://googledrive.com/host/[folder ID]/) and simply append the newly created file names. I asked a question related to this topic a few days ago.
Conversely, you can set the permissions for each file you create then get the download URL's for them individually using getDownloadUrl().