[Django]-Locating file path from a <InMemoryUploadedFile> Django object

14👍

Surely the name “InMemory” is a clue that the file exists in memory only, so doesn’t have a path?

1👍

Daniel Roseman is correct for the context. But if you already created/inserted the object into the database using .create(...) or obj.save(). The path of the image can be retrieved by using obj.<field_name>.name.
Example:

Suppose you have a model with an image field.

my_image = models.ImageFiled(upload_to='my_upload_dir')

so,

obj = ImageModel.objects.create(image=request.FILES['image']) # let's insert it to db
image_path = obj.image.name

# will return 
'my_upload_dir/myimagename.jpg'

Leave a comment