Google Drive File Name Automatically Replaced when User download the file - google-drive-api

Google Drive Screenshot
I have one Video file in my Google Drive with the name Perfect.mp4 and I have created a direct download link of this file with Google Drive API. So User can Download this File Without this Warning ( Google Drive can't scan this file for viruses ) but the problem is
when any user downloads this my video file: Perfect.mp4.
Then The name of my video is automatically renamed with the FIELD ID and the file extension is also gone.
This is My Link: https://www.googleapis.com/drive/v3/files/1nRLV1rEcQddkWJ6nGCCdsCvemSp_mqza?alt=media&key=AIzaSyCj8FQUm-Su55PRIQbTZ2BHc9gY8BDr4vE
The filename of my video is correct in my Google Drive account but When Any User Downloads my video file with this link then only The name of my video is automatically renamed with the FIELD ID and the user sees any random file id name instead of my original file name.
Please help me to solve this problem

You should use the webContentLink:
https://drive.google.com/uc?id=1nRLV1rEcQddkWJ6nGCCdsCvemSp_mqza&export=download.
It is not a good idea to share your API key.

Related

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

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.

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 API - share(copy) my file automatically to user drive account

the scenario is like this. I have a file in Google Drive, then share it to public, but not the direct link to my file. see sample here https://ganool.ag/steve-jobs-2015-bluray-720p-ganool-ag/ | scroll down and find link https://file.rocks/file/jBH0tM97Ne (ignore the pirate movie in the link, it's just sample). When you click the link, the file will be copied to your drive account, save in a folder called File.rocks, than a subfolder with random name.
my question is, what API command used in that script? just the concept, not the complete script.
sorry for my english.
The behavior shown in that website is similar to the Save to Drive button which allows the user to save files to their Drive account from an arbitrary URL via their browser.
The technology used to upload files is similar to that used by the Google Drive web user interface. The file is downloaded to the user's browser in parts and uploaded to Google Drive as data is received.
Authorize your app to get code
exchange code for token
create client-folder-id if not exist
then use copy
for example:
POST https://www.googleapis.com/drive/v3/files/<your-file-id>/copy
Authorization: Bearer token...xxxxxx
{
"parents": [
"<client-folder-id>"
]
}

Can I add a web page as a document to google drive

I would like to add a 'file' to my drive which is simply a link to a website/page. I have tried creating a file with alternateLink and webContentLink fields specified but they just get overwritten.
I want to be able to store the link in Drive, retrieve it and use it in my app at a later date.
You can but not like that. You can:
1) write your own custom file and store the link as file data
2) additionally if you want the link to open from drive you can (unlike a comment in this question that saus you cant) by writting a Drive app and handle the file-open. See https://support.google.com/drive/answer/2500820?hl=en
What I was looking for was the 'shortcut' mimetype : "application/vnd.google-apps.drive-sdk", as described in create_a_shortcut_to_a_file. When I create a file with that mimeType, the alternateLink does not get overwritten. A 'file' is created in my drive and I can use the alternateLink to navigate to tghe page.