Amazon S3存储Wagtail媒体文件-仅Heroku上的服务器500错误

问题描述:

我一直在关注使用Amazon S3存储Wagtail媒体文件博客文章,以设置Amazon s3来存储我的w媒体文件

I have been following the Using Amazon S3 to Store Wagtail Media Files blog post to set up amazon s3 to store my wagtail media files

这在我的本地开发服务器上非常有效(所有图像均按预期显示在S3存储桶中).但是,在Heroku上进行部署时,由于上载程序完成并且图像未保存在S3存储桶中,因此出现服务器500错误.除了此行外,heroku日志中没有其他详细信息.这使得调试非常困难.我没有将S3用于我的静态资产(这些资产是由whitenoise处理的.将debug更改为True没什么区别.任何建议都非常感谢.

This works perfectly on my local development sever (all of the images appear in the S3 bucket as expected). However in deployment on Heroku I get a server 500 error just as the uploader completes and the images are not saved in the S3 bucket. There is no detail in the heroku logs other than this line. Which makes it very difficult to debug. I am not using S3 for my static assets (these are handled by whitenoise. Changing debug to True makes no difference. Any advice greatly appreciated.

2018-08-19T16:56:43.517786 + 00:00 app [web.1]:10.7.223.133--[19/Aug/2018:16:56:43 +0000]"POST/admin/images/multiple/add/HTTP/1.1"500 363" https://isawebsite.herokuapp. com/admin/images/multiple/add/

github存储库

更新:通过尝试通过django-admin界面而不是w上传器上传图像,我得到了更多有用的错误消息. 调用PutObject操作时发生错误(InvalidAccessKeyId):您提供的AWS访问密钥ID在我们的记录中不存在.我不理解这一点,因为这些密钥在我的.env文件中绝对正确并推送到heroku配置.密钥在本地和AWS CLI中工作.

Update: by trying image upload via the django-admin interface rather than wagtail uploader I got a more informative error message. An error occurred (InvalidAccessKeyId) when calling the PutObject operation: The AWS Access Key Id you provided does not exist in our records. I don't understand this because the keys are definitely correct in my .env file and are pushed to heroku config. The keys work locally and in AWS CLI.

我们解决了这个问题-Heroku中AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY的配置值包括引号,例如'QWERTY12345'而不是QWERTY12345.它在本地有效,因为python-dotenv删除了.env文件中的引号:

We worked this out - the config values in Heroku for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY included surrounding quotes, e.g. 'QWERTY12345' rather than QWERTY12345. It worked locally because python-dotenv strips surrounding quotes from .env files:

https://github.com/theskumar/python-dotenv/blob/master/dotenv/main.py#L43

我已经在 https://wagtail上更新了博客文章. io/blog/amazon-s3-for-media-files/进行澄清.