zoukankan      html  css  js  c++  java
  • Edit Static Web File Http Header Metadata of AWS S3 from SDK | SDK编程方式编辑储存在AWS S3中Web类文件的Http Header元数据

    1.Motivation | 起因

    A requirement from the product department requires download image from AWS S3 bucket, for achieving this requirement, I should set the image content MIME header as Content-Disposition:Attachment.

    产品部门有一项需求是从S3上下载图片,为了完成这一需求,需要把图片的MIME头设为Content-Disposition:Attachment

    2.Attemption | 尝试

    I tried pre-handling before upload the image file to S3 with the metadata by the following method:

    尝试了以下面的方法在文件上传到S3之前进行预处理。

    var request = new Amazon.S3.Model.PutObjectRequest()
    {
        FilePath = @"D:SourceFile.jpg",
        BucketName = @"MyBucket",
        Key = @"Folder/NewFileName.jpg",
        ContentType= "images/jpg",
        CannedACL=S3CannedACL.PublicRead,
    };
    request.Metadata.Add("Cache-Control", "no-store");
    

    But the result shows that the uploaded file is attached a strange metadata as x-amz-meta-Content-Disposition:Attachment, it's not suitable for my propose.

    但结果显示上传的文件被附带了奇怪的元数据:x-amz-meta-Content-Disposition:Attachment,这并非我的本意。

    3.Resolved | 解决

    Finally I found that the request has a property named Header and it has the typical http header keys such as CacheControl and ContentEncoding, certainly the ContentDisposition is in it too. So I modified the assignment as follow and the requirement can be done.

    最终发现,请求体中有个名为Header的属性,该属性具有一些典型的http头中的键,像CacheControlContentEncoding,当然ContentDisposition也在其中。于是如下面的代码这样修改了赋值语句,就搞定了这项工作。

    request.Headers.ContentDisposition = "attachment";
  • 相关阅读:
    [学习笔记]Java代码中各种类型变量的内存分配机制
    记录一次linux线上服务器被黑事件
    浅谈Facebook的服务器架构(组图)
    make: *** [sapi/cli/php] Error 1 解决办法
    linux CentOS 系统下如何将php和mysql命令加入到环境变量中
    Linux系统安装Apache 2.4.6
    日请求亿级的QQ会员AMS平台PHP7升级实践
    聊一聊淘宝首页和它背后的一套
    PHP与MySQL通讯那点事
    PHP多进程(4) :内部多进程
  • 原文地址:https://www.cnblogs.com/qushuiliushang/p/13069782.html
Copyright © 2011-2022 走看看