Sto usando django-storages
con s3boto
come back-end.Come si imposta "Content-Type" quando si salva su S3 usando django-storages con il backend S3boto?
Ho un secchio con due cartelle: uno per static
e uno per media
. Realizzo questo utilizzando django-s3-folder-storage
.
Oltre a salvare su S3 utilizzando un modello, voglio anche implementare una funzione di ridimensionamento dell'immagine e cache per salvare i file su S3. Per farlo interagisco direttamente con il mio secchio S3. Il codice funziona, ma lo Content-Type
non è impostato su S3.
in ipython:
In [2]: from s3_folder_storage.s3 import DefaultStorage
In [3]: s3media = DefaultStorage()
In [4]: s3media
Out[4]: <s3_folder_storage.s3.DefaultStorage at 0x4788780>
prova stiamo accedendo il secchio giusto - storage_test
è uno che ho creato in precedenza:
In [5]: s3media.exists('storage_test')
Out[5]: True
In [6]: s3media.open("test.txt", "w")
Out[6]: <S3BotoStorageFile: test.txt>
In [7]: test = s3media.open("test.txt", "w")
In [8]: test
Out[8]: <S3BotoStorageFile: test.txt>
In [9]: test.key.content_type = "text/plain"
In [10]: test.write("...")
In [11]: test.close()
In [12]: test = s3media.open("test.txt", "w")
In [13]: test.key.content_type
Out[13]: 'binary/octet-stream'
Ho anche cercato invece di utilizzare In [9]
test.key.metadata
e test.key.set_metadata
. Nessuno di loro lo fa.
Come si imposta il tipo di contenuto corretto?