1
1.It looks like db_file_storage.storage.save() expects their custom format specified to be used with the model plus the filename e.g. “console.ConsolePicture/bytes/filename/mimetype” + filename.
So for your example instead of
'report.pdf'
it would be
'restaurants.InspectionFile/bytes/filename/mimetype/report.pdf'
I looked at the documentation and it isn’t clear why it’s being done this way as this violates DRY by making you enter the same thing twice, but they use the same format throughout the DatabaseFileStorage class.
2.It also looks like there’s a bug in the save method (line 60) where
mimetype = content.file.content_type
should be changed to
mimetype = content.content_type
And the file you pass it should be something with a content_type attribute so probably a Django SimpleUploadedFile:
from django.core.files.uploadedfile import SimpleUploadedFile
file_ = SimpleUploadedFile('report.pdf', open('/docs/Data/2011/12/12-07-11_1498.pdf', 'r').read())
The reason I think this is a bug is that when I tried passing in a mock object that looked like “content.file.content_type” I got a Python core library exception later on.