barseghyanartur / django-fobi

Form generator/builder application for Django done right: customisable, modular, user- and developer- friendly.
https://pypi.python.org/pypi/django-fobi
484 stars 112 forks source link

media file storing in aws is not working. #250

Open saileshkush95 opened 4 years ago

saileshkush95 commented 4 years ago

I'm trying to store media files and static files in aws but it is now working for media files. Static files is working perfectly.

barseghyanartur commented 4 years ago

See this. That handle_uploaded_file might not work on AWS. You could come up with something using django-storages or use Boto directly. It all comes down to copying the existing file plugin, renaming it to aws_file and making correspondent changes.

PRs are welcome.

saileshkush95 commented 3 years ago

Sorry I'm little but busy, so I'm unable to follow this issue anyway thank you for your response. I'm already using django-storages and boto3. and here is my code snippets.

# AWS Configurations
AWS_ACCESS_KEY_ID = config('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = config('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = config('AWS_STORAGE_BUCKET_NAME')
AWS_DEFAULT_ACL = None
AWS_S3_OBJECT_PARAMETERS = {
    'CacheControl': 'max-age=86400',
}
AWS_S3_FILE_OVERWRITE = False

from storages.backends.s3boto3 import S3Boto3Storage  # noqa E402

AWS_S3_REGION_NAME = config('AWS_S3_REGION_NAME')
AWS_STORAGE_BUCKET_NAME = config('AWS_STORAGE_BUCKET_NAME')

class StaticRootS3Boto3Storage(S3Boto3Storage):
    default_acl = 'public-read'
    location = 'static'
    custom_domain = f'{AWS_STORAGE_BUCKET_NAME}.s3.{AWS_S3_REGION_NAME}.amazonaws.com'

class MediaRootS3Boto3Storage(S3Boto3Storage):
    file_overwrite = False
    default_acl = 'public-read'
    location = 'media'
    custom_domain = f'{AWS_STORAGE_BUCKET_NAME}.s3.{AWS_S3_REGION_NAME}.amazonaws.com'

STATICFILES_STORAGE = 'config.settings.pro.StaticRootS3Boto3Storage'
STATIC_URL = f'https://{AWS_STORAGE_BUCKET_NAME}.s3.ap-south-1.amazonaws.com/ static/'
# # endregion
# DEFAULT_FILE_STORAGE = 'config.settings.pro.MediaRootS3Boto3Storage'
# MEDIA_URL = f'https://{AWS_STORAGE_BUCKET_NAME}.s3.ap-south-1.amazonaws.com/media/'

As for now I'm storing media files in my server, But i didn't want to do that. I want to store all of the media files upload by the user in the aws storage.

To make this work do i need to override this handle_uploaded_file method

barseghyanartur commented 3 years ago

Yep. That's what I said. It comes down to making a new plugin with adjusted handle_uploaded_file method.

saileshkush95 commented 3 years ago

So here, handling media files is not dependent on default django storage backend.?

barseghyanartur commented 3 years ago

See this and this.