简体   繁体   中英

What is the best way to Identify Google drive url?

I'm working on a project where I need to upload files to Google Drive. Files can be in any format such as Image, Document or Video.

I can see that google drive returns same URLs for all content types. For example:

URL for Document: https://drive.google.com/open?id=0B11bZBQ5dfsdferRER

URL for Image: https://drive.google.com/open?id=0B11bZBQ5ererWEEWssdfd

Upload part is done but I'm facing issue while showing files on webpage because I want to identify the content type of the URL to render differently for each files.

Possibly I can download the file from the URL and then get the content-type before rendering. But it's a last option for me because files may be larger in size and numbers.

Is there any easy solution around web so that I don't need to download each url to get only content type?

Well, it's possible, as long as you have stored the files in a public folder.

you can then recognize the files based on the url, which would be something like this: googledrive.com/host/folderID/filename

Some more information on this can be found here .

You can use the Drive API to get file metadata given you have the file ID and at least reader permission role for the file.

And you can extract the file ID from the URLs by taking the id query parameter.

See Drive API files get method: https://developers.google.com/drive/v3/reference/files/get

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM