【发布时间】:2020-07-18 18:31:11
【问题描述】:
所以,我正在尝试将 HTML 文件上传到我的Aws s3,该文件正在上传,但它不会在浏览器中呈现为 HTML 文件。
def upload_coverage_s3
path_to_file = Rails.root.to_s+'/public/coverage/index.html'
file = File.open(path_to_file)
aws_path = "test_coverage/#{Time.now.to_i}/index.html"
uploadObj = AwsHelper.upload_to_s3_html(aws_path,file)
uploadObj[:url]
end
def self.upload_to_s3_html(path,file)
if path.nil? || path.blank?
puts 'Cannot upload. Path is empty.'
return
end
obj = S3_BUCKET.objects[path]
obj.write(
file: file,
content_type: "text/html",
acl: :public_read
)
upload = {
url: obj.public_url.to_s,
name: obj.key
}
upload
end
我得到一个带有加载 gif 的白屏
我点击了这个链接
Upload HTML file to AWS S3 and then serving it instead of downloading
因为我想要类似的功能uploading HTML file and then serving as an HTML file instead of downloading
PS: 我也在我的 s3 存储桶中手动上传了那个 HTML 文件,问题是一样的。 如何解决。 s3不支持HTML文件上传吗?
【问题讨论】:
标签: ruby-on-rails amazon-web-services amazon-s3 aws-sdk