Reputation: 93
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
.
Upvotes: 1
Views: 204
Reputation: 8294
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.
Upvotes: 2