1

I was downloading Revit models from BIM360 team hub via ForgeAPI using the following uri.

https://developer.api.autodesk.com/oss/v2/buckets/:bucketKey/objects/:objectName

All my objectName ended with .rvt. So I downloaded and saved them as rvt file. However I noticed that some of the files cannot be opened by Revit. They are actually not rvt files but zip files. So I have to change the extension to .zip and unzip the file to get real 'rvt` files.

My Problem is that not all files is zip file. I cannot tell from the API because the URI I request is always ended with .rvt.

C3pLus
  • 93
  • 6

1 Answers1

2

Every Unix OS provides the file command, a standard utility program for recognising the type of data contained in a computer file:

https://en.wikipedia.org/wiki/File_(command)

A zip file is directly recognised and reported like this:

$ file test_dataset.zip
test_dataset.zip: Zip archive data, at least v2.0 to extract

A Revit RVT model is a Windows compound document file, so it generates the following output:

$ file little_house_2021.rvt
little_house_2021.rvt: Composite Document File V2 Document, Cannot read section info

Hence you can use the same algorithm as file does to distinguish between RVT and ZIP files.

Afaik, file just looks at the first couple of bytes in the given file.

The Python programming language offers similar utilities; try an Internet search for distinguish file type python; the first hits explain How to check type of files without extensions in Python and point to the filetype Python project.

Other programming languages can provide similar functionality.

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • Thank you for your answer. I may not express clear. The problem is that. I download a file from "https://some_url/file.rvt" and save it to local as "file.rvt". However, this file is not always a true rvt file. Sometimes, even the download url is "https://some_url/file.rvt", the file itself's extension is rvt, but it is actually a zip file..I was seeking a way to tell if a file is rvt file or zip file regardless its extension. – C3pLus Jul 16 '20 at 05:09
  • I thought it is problem of Autodesk Forge. It marks the file to be a Revit file. But when you downloaded the file. It sometimes gives you a zip file rather than Revit file but still name it `.rvt`. – C3pLus Jul 16 '20 at 05:15
  • Just tried your method. `file` command does tell if the file is a zip file even its extension is `rvt`. Thank you so much. – C3pLus Jul 16 '20 at 05:21
  • My pleasure entirely. Glad it helped. – Jeremy Tammik Jul 17 '20 at 06:22