Hi Experts! I am trying to upload an image inside the following AWS S3 path: *pg-merchant/merchant/logos* But the image is uploading inside the following path:*pg-merchant* instead of storing inside the *logos *folder; pfa screen of the same.
<https://lh3.googleusercontent.com/-YfNR6BWPMZE/Wyd5178f7bI/AAAAAAAAMJ8/Huu1W1E0JWUxrpGEIodKgyCbDgiZBj5zwCLcBGAs/s1600/image%2Bpath%2Bissue%2Bin%2Bs3.JPG> I am suspecting there must be a mistake in my code but I am unable to find it out so need your help here. PFB my code snippet- *config.json*- { "AWS_STORAGE_BUCKET_NAME": "pg-merchant", "AWS_ACCESS_KEY_ID": "", "AWS_SECRET_ACCESS_KEY": "", "S3DIRECT_REGION": "us-east-1", } *settings.py*- AWS_STORAGE_BUCKET_NAME = ENV_TOKENS.get('AWS_STORAGE_BUCKET_NAME') AWS_ACCESS_KEY_ID = ENV_TOKENS.get('AWS_ACCESS_KEY_ID') AWS_SECRET_ACCESS_KEY = ENV_TOKENS.get('AWS_SECRET_ACCESS_KEY') AWS_BASE_DOMAIN = 's3.amazonaws.com' AWS_S3_CUSTOM_DOMAIN = '%s.%s' % (AWS_STORAGE_BUCKET_NAME, AWS_BASE_DOMAIN) STATIC_URL = '/static/' MEDIA_FILES_LOCATION = 'merchant' MEDIA_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, MEDIA_FILES_LOCATION) DEFAULT_FILE_STORAGE = 'ps_cms.custom_storages.MediaStorage' *models.py*- @property def logo(self): logo_name = '{}{}'.format(self.name, '.png') s3_key_name = os.path.join(settings.MEDIA_FILES_LOCATION, 'logos', logo_name) # Generate file URL bucket_name = settings.AWS_STORAGE_BUCKET_NAME s3_endpoint = settings.AWS_BASE_DOMAIN file_url = 'https://{}/{}/{}'.format(s3_endpoint, bucket_name, s3_key_name) return file_url forms.py- def _upload_logo(self, logo, merchant_name): ext = os.path.splitext(logo.name)[1] # [0] returns path+filename logo_name = '{}{}'.format(merchant_name, ext) s3_client = self._get_s3_client() s3_key_name = os.path.join(settings.MEDIA_FILES_LOCATION, 'logos', logo_name) s3_client.upload_fileobj(logo, settings.AWS_STORAGE_BUCKET_NAME, s3_key_name) # Generate file URL bucket_name = settings.AWS_STORAGE_BUCKET_NAME s3_endpoint = settings.AWS_BASE_DOMAIN new_file_url = 'https://{}/{}/{}'.format(s3_endpoint, bucket_name, s3_key_name) return new_file_url -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f319a0d4-9d68-4e6f-962f-346534a7d7ae%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.