Heroku + S3 AWS + Django!=没有图像

时间:2019-05-24 18:02:25

标签: django heroku amazon-s3

我试图将我的应用程序置于在线状态,但是似乎没有显示图像文件。也许你可以帮忙吗?我在S3 AWS的存储桶中需要图像,但是仍然没有任何显示。虽然当我尝试在网络侧打开图像时,我会被发送到亚马逊网站。然后我收到此消息:

  

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package pkg6.pkg24; /** * * @author HieuNguyen */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here for (int num = 1; num <= 1000; num++) { isItPerfectNumber(num); } } public static void isItPerfectNumber(int num) { int factor = 1; String factors = "Factors: "; int total = 0; while (factor < num) { if (num % factor == 0) { total += factor; factors += factor + " "; } factor++; } if (total == num) { System.out.printf("%s is perfect number\n", num); System.out.print(factors + "\n"); } } } 授权   您提供的机制不受支持。请用   AWS4-HMAC-SHA256。 8CF0C70490DEFEE2      dtBKlPBbw5L6pM6mGyd4YaqC4amay / c2tccfhhStjujVGG2qdrvQwD6vGloJZWQle9A5Cwr3Rws =    

InvalidRequest

1 个答案:

答案 0 :(得分:1)

您的MEDIA_URL不正确。

尝试类似的方法(假设您要用于静态资源和媒体):

AWS_AUTO_CREATE_BUCKET = True
AWS_STORAGE_BUCKET_NAME = "my_bucket"

DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
STATICFILES_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"

STATIC_LOCATION = "resources/"
MEDIA_LOCATION = "media/"

AWS_BUCKET_ACL = "public-read"
AWS_QUERYSTRING_AUTH = False
AWS_S3_REGION_NAME = "your-bucket-region"

AWS_S3_CUSTOM_DOMAIN = f"{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com"


STATIC_URL = f"https://{AWS_S3_CUSTOM_DOMAIN}/{STATIC_LOCATION}"
MEDIA_URL = f"https://{AWS_S3_CUSTOM_DOMAIN}/{MEDIA_LOCATION}/"