This commit is contained in:
Sam
2021-02-16 10:29:04 +00:00
parent f71f822dab
commit e471b57ec3

View File

@@ -77,28 +77,13 @@ class Command(BaseCommand):
response.raw.decode_content = True response.raw.decode_content = True
image = Image.open(response.raw) image = Image.open(response.raw)
# save using File object
img_io = BytesIO() img_io = BytesIO()
image.save(img_io, format='JPEG') image.save(img_io, format='JPEG')
# option 1: read image from memory
'''
product.image = InMemoryUploadedFile(
BytesIO(),
field_name=None,
name=f"{company.company_name}-{name}.jpg",
content_type='image/jpeg',
size=img_io.tell,
charset=None
)
'''
# option 2: File object
product.image.save(f"{company.company_name}-{name}.jpg", File(img_io), save=False) product.image.save(f"{company.company_name}-{name}.jpg", File(img_io), save=False)
product.save() product.save()
logging.debug(f"New Product {product.name} created") logging.debug(f"New Product {product.name} created")
print("*", end = '.')
# import ipdb; ipdb.set_trace()
print('') print('')
print("Dataset creation finished") print("Dataset creation finished")