ORACLE database that I use stores files in the PDF or ZIP format in the BLOB type. I want to save these files. However, I do not know how to recognize when it is a PDF and when it is ZIP? Is it possible to check which file format BLOB stores inside?
Below is a simple write_file method for saving a file:
def write_file(data, filename):
with open(filename, 'wb') as f:
f.write(data)
Here, I fetch the appropriate BLOB with the cursor and I use the write_file
method to save the file:
firstRow = cur.fetchone()
write_file(firstRow[0].read(), "blah.zip")
How to recognize when it will be zip and when it will be pdf?