Google Drive Url System Design - google-drive-api

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

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/

How to fetch the URL of an uploaded IMAGE or VIDEO from a GOOGLE FORM using GOOGLE APP 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.

API Changes for Google Drive’s folder structure and sharing models

I used to use below Google Drive API to move my existing file to another drive folder
drive.files().update(fileId=cloudFile['id'],addParents=sharefile,media_body=media).execute()
I just got an email said that the Google Drive folder structure is changed and I'm not allowed to use "addParent" to share filers anymore. I was wondering how can I do this with drive API? I don't want to re-write the entire code, and I'm looking for the simplest way to replace addParents API.
Answer:
Instead of giving a file multiple parents, you can create a shortcut to another Drive file instead (such as a folder).
More Information:
You can use the shortcuts functionality of Google Drive instead of the multiple parents functionality to emulate the kind of behaviour. From the Documentation:
Shortcuts are files that link to other files on Google Drive.
Shortcuts are Drive files with the application/vnd.google-apps.shortcut MIME type, that point to another file or folder on a Google Drive. You can read more about this here.
References:
Create a Shortcut to a Drive File
Find files & folders with Google Drive shortcuts
G Suite and Drive MIME Types

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.

Files in public folder on google drive not visible even via WebViewLink

So I've used a little Google Apps script to make a public folder (type: anyone, role: reader) and then I've requested and received the WebViewLink. But when I go to that link, it says there are no files. I've placed (via Google Drive web interface, not via the app script) an index.html file (document) in that folder.
Do I have to MAKE all the files in the folder via the app script?
I seem to have heard on one of the announcements about this that once the folder is created, you can just drop files into it.
Found the answer myself. The documents in the folder must be of the correct type or they just don't show up. E.g. a google docs document called index.html is NOT an html document. You have to create a standard html page locally and then upload it, but never open or edit it with google docs (drive, whatever) in order for it to be seen. I put detailed instructions on a web page hosted by Google Drive here:
https://googledrive.com/host/0B0ap0WDOII5mbjdwajNBMlRoZUU/