'Why does the returned metadata contain edit link for some file types for the webViewLink?

So I am using the Google Drive api to upload files to Google drive and when the upload is completed, I am opening the uploaded file by accessing the webViewLink property in the metadata that is returned. But for some file types it is returning edit link instead of view link, for example,

Edit link: "https://docs.google.com/document/d/1-ZvUwZj1aJRmVfUAlUnzy6PLbzRBZh/edit?usp=drivesdk&ouid=103011368539855&rtpof=true&sd=true" (for POT,DOTX,DOTM,DOT,DOCX,,DOCM,DOC,PPS,PPTX,PPT,XLS,XLT,XLSX files)

View link: "https://drive.google.com/file/d/16U6Zg_8t0A9P2HW_vGoS/view?usp=drivesdk" (for all other MS office files)

After some investigation on my own, I found out that this is because of the mime type associated with those particular file types. If I forcibly set the mime type to one which gave me the view link, then I get the view link for those file types which were giving me edit links.

So my question is, why does it return edit link based on this mime type? And what can we do to either get the edit link or view link (is there a way to specify this)? And if we forcibly set the mime type to some other value that works for me, what can go wrong?



Solution 1:[1]

Using the GTLRDriveQuery_FilesCreate query, we can specify which fields that google should return to us, and the id field that can be returned can be used to construct the view url.

let url = "https://drive.google.com/file/d/\(id)/view"

where id is the identifier of the file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Skywalker