2012-02-10 20 views
7

üzerinde bulunan dosyalarda content_type öğesini ayarlayın s3boto arka ucuna sahip django depoları kullanıyorum. Bu konuya göre, http://code.larlet.fr/django-storages/issue/5/s3botostorage-set-content-type-header-acl-fixed-use-http-and-disable-query-auth-by 'Uygulama/okt-akış' içerik türüne sahip bir sürü dosyam var (hepsi). <class 'boto.s3.key.Key'> örneğim olduğu için, içerik_türü nasıl ayarlayabilirim?Boto kullanarak, s3

In [29]: a.file.file.key.content_type 
Out[29]: 'application/octet-stream' 

In [30]: mimetypes.guess_type(a.file.file.key.name)[0] 
Out[30]: 'image/jpeg' 

In [31]: type(a.file.file.key) 
Out[31]: <class 'boto.s3.key.Key'> 

cevap

16

oluşturulduktan sonra bir dosya ile ilişkili içerik türünü (veya başka bir meta) değiştirmek için hiçbir yolu yoktur. Bununla birlikte, dosyayı sunucu tarafına kopyalayabilir ve işlemdeki meta verileri değiştirebilirsiniz.

https://gist.github.com/1791086

İçindekiler:

import boto 

s3 = boto.connect_s3() 
bucket = s3.lookup('mybucket') 
key = bucket.lookup('mykey') 

# Copy the key onto itself, preserving the ACL but changing the content-type 
key.copy(key.bucket, key.name, preserve_acl=True, 
    metadata={'Content-Type': 'text/plain'}) 

key = bucket.lookup('mykey') 
print key.content_type 

Mitch

İşte yardımcı olmalıdır github bir özü olduğunu
İlgili konular