Hello guys hope you doing well, I’m using Django Rest Framework (DRF) with DigitalOcean Spaces as my media storage backend. File uploads work perfectly in local development and in the shell of heroku environment but the API returns a 201 Created response with a valid file URL, yet the file is never actually stored in Spaces.
here is my productImage model
class ProductImage(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name=‘images’)
image = models.ImageField(upload_to=‘store/images’)
here is my productImageSerializer
class ProductImageSerializer(serializers.ModelSerializer):
def create(self, validated_data):
product_id = self.context[‘product_id’]
return ProductImage.objects.create(product_id=product_id, **validated_data)
class Meta:
model = ProductImage
fields = ['id', 'image']
here is the custom storage am using
from storages.backends.s3boto3 import S3Boto3Storage
class MediaStorage(S3Boto3Storage):
location = ‘media’
file_overwrite = False
default_acl = ‘public-read’
here is my prod.py
AWS_ACCESS_KEY_ID = os.environ.get(‘DO_SPACES_ACCESS_KEY’)
AWS_SECRET_ACCESS_KEY = os.environ.get(‘DO_SPACES_SECRET_KEY’)
AWS_STORAGE_BUCKET_NAME = ‘suuqcasri-storage’
AWS_S3_REGION_NAME = ‘nyc3’
AWS_S3_ENDPOINT_URL = ‘https://nyc3.digitaloceanspaces.com’
AWS_S3_CUSTOM_DOMAIN = f’{AWS_STORAGE_BUCKET_NAME}.nyc3.digitaloceanspaces.com’
DEFAULT_FILE_STORAGE = ‘storefront.storage_backends.MediaStorage’
MEDIA_URL = f’https://{AWS_S3_CUSTOM_DOMAIN}/media/’
please tell me how i can fix this issue