Вам нужно установить тип пантомимы.Расширения файлов не используются последовательно браузерами.
Когда вы сохраняете файл, делайте что-то вроде:
opt = [] # default options for the S3Object.Store call. See the method's
# source for info on all the options
epub = an_epub_file?(obj) # my private method to determine if I'm storing
# an epub file.
extname = File.extname(obj) # Gets the suffix from the file name. Eg ".js"
mimes = MIME::Types.type_for(obj) # if the mime library finds anything, an array
# of mime values is returned
mime = (mimes && mimes[0] && mimes[0].content_type) || # did we get a value from
# the mime library?
( # Nothing from the mime library. Sigh.
# Let's try other ways to get the right mime value...
case
when epub: "application/epub+zip"
when extname == ".js" : "application/x-javascript"
else "application/octet-stream" # default mime value
end)
opt[:content_type] = mime
AWS::S3::S3Object.store(obj, data, bucket, opt)
Обратите внимание, что в примере кода используется выражение case.Это НЕ утверждение случая.В выражении case используется совпадающее плечо case для возврата значения.
В приведенном выше операторе присваивания выражение case вычисляется, если левая часть выражения OR заканчивается false или null.
Я использовал выражение case, поскольку ожидал, что в будущем мне понадобится добавить другие специализированные типы пантомимы.