vishavjeet

singh.vishavjeet11@gmail.com

How can upload image from url in Django(python)

Posted on July 22, 2021



import urllib
import os
from django.core.files import File # you need this somewhere
image_url = request.data['image_url']
result = urllib.request.urlretrieve(image_url)
product_image = ProductImage(product_id=1, variant_id=46)
product_image.image_url.save(os.path.basename(image_url), File(open(result[0], 'rb')))
serializer = ProductImageSerializer(data=product_image)


Sign In for comment and like the post.