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";

Edit Static Web File Http Header Metadata of AWS S3 from SDK | SDK编程方式编辑储存在AWS S3中Web类文件的Http Header元数据的更多相关文章

  1. C#中web项目使用log4net日志

    我准备把log4net的实现方法放在一个类库项目中,别的项目直接引用该类库,即可进行日志的记录,操作步骤如下: 1.下载log4net.dll文件 2.在解决方案下创建类库项目 3.把log4net. ...

  2. web file

    Blob 对象表示一个不可变.原始数据的类文件对象 构造函数 var aBlob = new Blob( array, options ); var aFileParts = ['<a id=& ...

  3. PHP中WEB典型应用技术

    主要讲5个方面: PHP与web页面的交互:表单传值,文件的上传与下载 http协议 PHP的会话技术:cookie和session PHP的图像技术:GD库,图像的常见的制作和操作,验证码,二维码, ...

  4. javaWeb项目中web.xml的xsd( XML Schemas Definition)文件

    <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns="http://w ...

  5. Eclipse创建第一个Servlet(Dynamic Web Project方式)、第一个Web Fragment Project(web容器向jar中寻找class文件)

    创建第一个Servlet(Dynamic Web Project方式) 注意:无论是以注解的方式还是xml的方式配置一个servlet,servlet的url-pattern一定要以一个"/ ...

  6. Java IO_001.File类--文件或文件夹相关操作

    Java IO之File对象常用操作 File类:用于文件或文件夹或网址相关联的操作.可以关联或不关联文件(即关联不存在的文件).构造函数有: public File(String pathname) ...

  7. SpringMVC(十六):如何使用编程方式替代/WEB-INF/web.xml中的配置信息

    在构建springmvc+mybatis项目时,更常用的方式是采用web.xml来配置,而且一般情况下会在web.xml中使用ContextLoaderListener加载applicationCon ...

  8. eclipse中web项目部署以后jsp的java文件找不到问题(Tomcat配置serverlocations)

    我的开发环境:eclipse kepler (4.3)+tomcat7.0.42. 在我想看eclipse中web项目jsp文件被tomcat转换成java以后的java源文件的位置,发现正常情况下的 ...

  9. Servlet中Web.xml的配置详解

    1 定义头和根元素 部署描述符文件就像所有XML文件一样,必须以一个XML头开始.这个头声明可以使用的XML版本并给出文件的字符编码. DOCYTPE声明必须立即出现在此头之后.这个声明告诉服务器适用 ...

随机推荐

  1. ODEINT 求解常微分方程(1)

    An example of using ODEINT is with the following differential equation with parameter k=0.3, the ini ...

  2. linux下操作memcache的操作命令

    1.连接memcache linux下一般使用telnet连接memcache服务 [root@localhost ~]# telnet 127.0.0.1 11266 Trying 127.0.0. ...

  3. 003.OpenShift网络

    一 OpenShift网络实现 1.1 软件定义网络(SDN) 默认情况下,Docker网络使用仅使用主机虚机网桥bridge,主机内的所有容器都连接至该网桥.连接到此桥的所有容器都可以彼此通信,但不 ...

  4. Springboot项目整合Swagger2报错

    SpringBoot2.2.6整合swagger2.2.2版本的问题,启动SpringBoot报如下错: Error starting ApplicationContext. To display t ...

  5. LevelDB/Rocksdb 特性分析

    LevelDb是Google开源的嵌入式持久化KV 单机存储引擎.采用LSM(Log Structured Merge)tree的形式组织持久化存储的文件sstable.LSM会造成写放大.读放大的问 ...

  6. unknown directive "" in E:\canteen\nginx-1.16.0/conf/nginx.conf:3-------文本编辑器修改nginx配置文件的坑

    nignx小白一个,今天在配置nginx的时候,理所当然的用了文本编辑器编辑并保存了一下nginx的nginx.conf配置文件,一不小心就折腾了几个钟. 保存之后就nginx -s reload一下 ...

  7. ImageLoader在ViewPage中的使用

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  8. 组合注解(Annotation)

    import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.an ...

  9. 暑假集训Day0

    啊这 跟学长学的要写日记 希望到时候能写省选集训的总结 咳咳 今天上午做了一上午苦力好像让老苏夸了难以接受(年纪两百考到年级两千他居然没有干我) 上午搞卫生搞到了十点半………… 替女生拉包提东西了!! ...

  10. ceph对象存储RADOSGW安装与使用

    本文章ceph版本为luminous,操作系统为centos7.7,ceph安装部署方法可以参考本人其他文章. [root@ceph1 ceph-install]# ceph -v ceph vers ...