Tôi hiện đang lưu trữ một loạt tệp .docx trong GAB Blobstore. Gần đây tôi đã nhận thấy rằng các tệp này đang tải xuống mà không có phần mở rộng tệp trên một số máy tính (IE 9 cho Windows 7), nhưng hoạt động tốt cho những người khác (IE 8, Chrome dành cho Windows 7).GAE đã tải xuống các tiện ích mở rộng tệp từ blobstore
Đây là cách các tập tin được lưu trữ trong các blobstore:
f = files.blobstore.create(mime_type='application/vnd.openxmlformats-officedocument.wordprocessingml.document',
_blobinfo_uploaded_filename=filename)
## then some code to write data and save ##
Dưới đây là các tiêu đề phản ứng cho các tập tin từ thanh tra Chrome:
Cache-Control:no-cache
Content-Disposition:attachment; filename="causes_of_ww1_emanresu"
Content-Length:12120
Content-Type:application/vnd.openxmlformats-officedocument.wordprocessingml.document
Date:Fri, 26 Oct 2012 23:54:09 GMT
Server:Google Frontend
X-AppEngine-Estimated-CPM-US-Dollars:$0.000033
X-AppEngine-Resource-Usage:ms=15 cpu_ms=0
Dưới đây là làm thế nào tôi phục vụ blob:
self.send_blob(blob_info, save_as=blob_info.filename, content_type=blob_info.content_type)
Tôi thậm chí đã cố gắng mã hóa cứng content_type='application/vnd.openxmlformats-officedocument.wordprocessingml.document'
không có kết quả.
Bất kỳ ý tưởng nào về những gì đang diễn ra và cách khắc phục?
Theo yêu cầu, dưới đây là cách tôi nhận thông tin tệp khi lưu ban đầu. Tôi chắc chắn rằng lỗi không xảy ra ở cấp độ này, nhưng đây là tiền thân của sự cố:
# get the file from a file_url with urlfetch
result = urlfetch.fetch(file_url)
headers = result.headers
# some custom functions to return a filename
username = self.get_username()
filename = get_filename(title, username)
# write the file to blobstore
f = files.blobstore.create(mime_type=headers['content-type'],
_blobinfo_uploaded_filename=filename)
with files.open(f, 'a') as data:
data.write(result.content)
files.finalize(f)
blob_key = files.blobstore.get_blob_key(f)
Bạn gửi lại đốm màu bằng cách nào? send_blob? –
Vâng, tôi đang sử dụng 'self.send_blob (blob_info, save_as = blob_info.filename)' – kennysong
Bạn có thể đăng mã thực sự tính toán 'filename', để chắc chắn nó có phần mở rộng. Ngoài ra, bạn có thể kiểm tra bằng cách sử dụng BlobInfo rằng tên tệp được lưu trữ với phần mở rộng phù hợp. –