1def save(self):
2 encodedString = base64.b64encode(self.item_image.file.read())
3 data = {"key": os.environ.get("IMG_BB"), "image": encodedString.decode("utf-8")}
4 uploadedImageInfo = requests.post("https://api.imgbb.com/1/upload", data=data)
5 jsonResponse = json.loads(uploadedImageInfo.text)
6 self.item_image_url = jsonResponse["data"]["display_url"]
7 super().save()
8
1class ProductSerializer(serializers.ModelSerializer):
2 class Meta:
3 model = Product
4 fields= ('id', 'item_title', 'item_desc', 'item_price', 'item_image_url')
5
1class Product(models.Model):
2 item_title= models.CharField(max_length=50)
3 item_desc=models.TextField()
4 item_price=models.IntegerField()
5 item_image=models.ImageField(upload_to='post_images',default='default.png')
6 item_image_url = models.TextField()
7