wqpnutrition.blogg.se

B2 blaze
B2 blaze










b2 blaze

I store the photo on the server that Django is running on, in a temp_photos folder. I am creating a TempPhoto object with the photo file and other data I want to store with it. In the meantime I've come up with a reasonable solution for this. Photo = forms.FileField(widget=forms.ClearableFileInput(attrs=))įrom import Storageįrom import deconstructibleī2 = B2(key_id=settings.B2_KEY_ID, application_key=settings.B2_APPLICATION_KEY)ī(contents=content, file_name=name)įilename, file_extension = os.path.splitext(filename) (thumb_filename, ContentFile(temp_thumb.read()), save=True)Ĭlass PhotoForm(LoggingMixin, forms.ModelForm): Thumb_filename = thumb_name + '_thumb' + thumb_extension Thumb_extension = thumb_extension.lower() Thumb_name, thumb_extension = os.path.splitext() Image.thumbnail(THUMB_SIZE, Image.ANTIALIAS) Thumbnail = models.ImageField(storage=B2Storage(), unique=True) Photo = models.ImageField(storage=B2Storage(), unique=True) Thanks! models/photo.py import osįrom import ContentFileįrom fotoplatform.storage import B2Storage If anyone could give me an approach I should be taking I would greatly appreciate it. I also have included the code of the custom B2Storage class. I thought about doing this in the PhotoForm with an overridden save() method but I was not able to find how to do this. I am just looking for a way to make this more efficient without downloading the full-size image again.

b2 blaze

I am using the code below to generate a thumbnail in the save() step of the Photo model and it works. Couldn't Django just keep the uploaded photo in memory (or temporary local storage), build a thumbnail and upload both the full-size image and the thumbnail to B2 afterwards? The downloading of the full-size image step seems unnessecary to me as the file is already uploaded through the Django webserver. Photo's are uploaded to Django, which in turn uploads the photo to B2, then it downloads it again, creates a thumbnail and uploads the thumbnail to B2. My plan was to use thumbnails for photo browsing, these need to be generated automatically. I am building a photo viewing and storing website using Django and Backblaze B2 and I have a lot of large (filesize) photo's that I am planning to upload on it.












B2 blaze