class myModel(models.Model):
myfile = models.FileField(storage=grid_fs_storage)
class Meta:
db_table = 'myModel'
I use drf-spectacular with multipart-parser to upload the file and get the following entry in the database:
myModel collection: myfiles.files collection:
{ "_id": { "$oid": "62325e25e9c2c70bf38c8840" },
"filename": "testfile.txt",
"contentType": "text/plain",
"md5": "23ab190c3786a60d569795b473e34683",
"chunkSize": 261120,
"length": { "$numberLong": "90" },
"uploadDate": { "$date": "2022-03-16T22:01:09.071Z"}
}
my endpoint returns on the post request:
my view looks like:
class FileView(ListCreateAPIView):
parser_classes = ( MultiPartParser,)
serializer_class = myModelSerializer
queryset = myModel.objects.all()
class myfiles(ListAPIView):
parser_classes = ( MultiPartParser,)
serializer_class = myModelSerializer
queryset = myModel.objects.all()
my urls.py looks like
...
urlpatterns=[
re_path(r'^api/teststandards/file', api.FileView.as_view(), name='teststandard-file'),
re_path(r'^myfiles', api.myfiles.as_view(), name='get-file'),
]
I don't know how my view or the serializer should look like to return the file again?
How do I retrieve the file from the database with gridfs?
Any help is appreaciated. A small example to follow would be great!!!
regards