2012-02-10 25 views
7

पर मौजूद हैं मैं s3boto बैकएंड साथ Django भंडार का उपयोग कर रहा पर Boto, सेट content_type का उपयोग करना। इस समस्या के अनुसार, http://code.larlet.fr/django-storages/issue/5/s3botostorage-set-content-type-header-acl-fixed-use-http-and-disable-query-auth-by मेरे पास फाइलों का एक समूह है (उनमें से सभी) जिनमें सामग्री प्रकार 'एप्लिकेशन/ऑक्टेट-स्ट्रीम' है। यह देखते हुए कि मेरे पास <class 'boto.s3.key.Key'> का उदाहरण है, मैं content_type कैसे सेट कर सकता हूं?फ़ाइलें जो पहले से ही 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'> 

उत्तर

16

फ़ाइल के निर्माण से उत्पन्न सामग्री प्रकार (या कोई अन्य मेटाडाटा) को संशोधित करने का कोई तरीका नहीं है। हालांकि, आप सर्वर की ओर से फ़ाइल की प्रतिलिपि बना सकते हैं और प्रक्रिया में मेटाडेटा को संशोधित कर सकते हैं।

https://gist.github.com/1791086

सामग्री::

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 

मिच

यहाँ GitHub पर एक सार है कि मदद करनी चाहिए है
संबंधित मुद्दे