I would like to store images directly into the database i have been trying
this but does not seem to help or i may be doing it in the wrong way''
models.py
from database_storage import DatabaseStorage
DB_FILES = {
'table': 'files',
'base_url': '/blog/attach/',
}
class Img(models.model):
uploaded_map_16 = models.ImageField(upload_to="map_images",
storage=DatabaseStorage(DB_FILES), null=True, blank=True)
uploaded_map_17 = models.ImageField(upload_to="map_images",
storage=DatabaseStorage(DB_FILES), null=True, blank=True)
uploaded_map_18 = models.ImageField(upload_to="map_images",
storage=DatabaseStorage(DB_FILES), null=True, blank=True)
this is how i am trying to save it:
storage = DatabaseStorage(DB_FILES)
image_file1 = open(file_name_18, 'rb')
file_content1 = image_file1.read()
image_file2 = open(file_name_17, 'rb')
file_content2 = image_file2.read()
image_file3 = open(file_name_16, 'rb')
file_content3 = image_file3.read()
Img.uploaded_map_18 = storage.save(name + '_18.jpg', file_content1)
Img.uploaded_map_17 = storage.save(name + '_17.jpg', file_content2)
Img.uploaded_map_16 = storage.save(name + '.jpg', file_content3)
Img.save()
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/daab6617-6f93-45c2-b3a8-751d77b85191%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.