1

I've found out how to load images from the file system into Django, but how do you get them out?

I've figured out how to get stuff from the database in my management command and can do a query like:

for m in my_models.objects.filter(get=some):
    image = m.image 
    # How do I copy this to another non-django location?
Zulu
  • 8,765
  • 9
  • 49
  • 56

1 Answers1

2

Images (or other FileFields) are actually regular files stored in somewhere (like a file system or a block storage like S3). Assuming that your files reside on the server's file system, you can use the path property to get the original file path and use Python shell utilities to copy it to another location:

import shutil

for m in my_models.objects.filter(get=some):
    image = m.image 
    shutil.copy(image.path, '/var/tmp/')
Selcuk
  • 57,004
  • 12
  • 102
  • 110