Search code examples
google-drive-api

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

  • why does it return edit link based on this mime type?

    • Some MS office files can be viewed/edited when opened in your Drive using either Google Docs, Sheets, or Slides, such files will have an edit link in its webViewLink (you can also check it directly in the drive, using Get Link). See Open Office files in Drive

    Additional Reference: Google has made the editing office files easier


    what can we do to either get the edit link or view link (is there a way to specify this)?

    • As stated in the previous answer, Files will have an edit link if the file can be viewed/edited when opened in your Drive using either Google Docs, Sheets, or Slides. Other unsupported files will have a view link.
    • There is no other way to get specific link other than changing its file type (mime type)

    if we forcibly set the mime type to some other value that works for me, what can go wrong?

    • This is quite a vague question, when you upload a file to your drive as long as the mimetype is supported, you can open it with the suggested options in your drive using open with. See supported file types