2

My understanding of S3 is

You don't want your client hit your server then hit s3 via urls.py. Your client is better off getting files(images) from s3 directly.
Therefore you will want to return the whole url(image_field.url) rather than relative path(image_field.name or similar) to your client to use.
But then, what if you move from S3 to some other service?

Returning whole URL to client would be an OK practice assuming you might want to switch from amazon S3 to something else later?

4

1 に答える 1

6

MEDIA_URLアップロードされたBASE_URLすべてのアセットの です。デフォルトでは、Django はアップロードされたファイルの相対パスをデータベースに保存します。

S3 を使用している場合は、 http://yourbucket.s3.amazonaws.com/MEDIA_URLなどのバケット URL に設定する必要があります。

その後、他のサービスに移行した場合は、MEDIA_URL設定を変更できます。それはとても単純なはずです。

于 2013-01-22T17:13:07.900 に答える