# idea: s3 module to auto detect content type and set as metadata

**URL:** <https://forum.ansible.com/t/idea-s3-module-to-auto-detect-content-type-and-set-as-metadata/16041>\
**Category:** Ansible Project\
**Created:** [August 26, 2014, 2:22pm UTC](https://forum.ansible.com/t/idea-s3-module-to-auto-detect-content-type-and-set-as-metadata/16041 "2014-08-26T14:22:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jake\_Clarkson](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@Jake\_Clarkson](https://forum.ansible.com/u/Jake_Clarkson)\
**Post date:** [August 26, 2014, 2:22pm UTC](https://forum.ansible.com/t/idea-s3-module-to-auto-detect-content-type-and-set-as-metadata/16041/1 "2014-08-26T14:22:39Z")

</div>

Hi all,

I’m in the process of uploading our static assets to S3 via an ansible task.

As this bucket is going to be sitting behind Cloudfront I really need the Content-Type HTTP response header to be set correctly.

Instead of us all having to do this manually every time (via the metadata property of the task) how about if the s3 module did this automatically? Something like:

```auto
- name: upload images to s3 bucket
s3: bucket=my_bucket object={{ item }} src={{ item }} mode=put
with_fileglob:
- web/images/*.png

```

And then have this adding in some metadata of “Content-Type: image/png” automatically. There could be an option for something like ‘infer\_content\_type’ which could default to false.

Happy to have a crack at it if people think it’s worth it 🙂

Thanks,  
Jake

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 26, 2014, 11:00pm UTC](https://forum.ansible.com/t/idea-s3-module-to-auto-detect-content-type-and-set-as-metadata/16041/2 "2014-08-26T23:00:46Z")

</div>

We’d be open to a pull request on this subject I guess.

Would it run “file” against the tool to figure out the type? This doesn’t map 100% to MIME types, so curious how you’d go about it.

Extensions shouldn’t be made to be significant, IMHO. That’s a little old-school-windowsey.

---

<div class="post-metadata">

**Author:** ![Drake\_Wilson](https://avatars.discourse-cdn.com/v4/letter/d/8e7dd6/32.png) [@Drake\_Wilson](https://forum.ansible.com/u/Drake_Wilson)\
**Post date:** [August 26, 2014, 11:17pm UTC](https://forum.ansible.com/t/idea-s3-module-to-auto-detect-content-type-and-set-as-metadata/16041/3 "2014-08-26T23:17:22Z")

</div>

That's still in very widespread use, and not only in Windows-based environments, and it's vastly  
more robust than trying to deal in potentially-colliding magic numbers; e.g., the latter means  
hooking up to existing preprocessing systems that attempt to ensure that all output files will  
be interpreted within a restricted set of types by name becomes impossible. ("widespread" here  
includes things like Apache and nginx both frequently being configured to use such a mapping  
by default.)

Filesystem-level extended attributes would be cleaner than encoding in the name, but are less  
convenient to output in a lot of environments. magic(4) (including file(1)) could be really  
dangerous here; you might be able to play around with filtering the set of recognized types,  
but egh.

Modern GNU/Linux machines often have /etc/mime.types, which maps extensions to media types.

&nbsp;&nbsp;&nbsp;---\> Drake Wilson

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 27, 2014, 12:20pm UTC](https://forum.ansible.com/t/idea-s3-module-to-auto-detect-content-type-and-set-as-metadata/16041/4 "2014-08-27T12:20:01Z")

</div>

“That’s still in very widespread use”

Yes, I’m aware people use file extensions. What I’m saying is you can’t trust them 🙂

" and it’s vastly  
more robust than trying to deal in potentially-colliding magic numbers"

Which is why we request you pass the type 🙂

---

<div class="post-metadata">

**Author:** ![Jake\_Clarkson](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@Jake\_Clarkson](https://forum.ansible.com/u/Jake_Clarkson)\
**Post date:** [August 28, 2014, 7:42am UTC](https://forum.ansible.com/t/idea-s3-module-to-auto-detect-content-type-and-set-as-metadata/16041/5 "2014-08-28T07:42:15Z")

</div>

Thanks for the responses guys. Although in my use case the extension can be trusted I agree to make it publicly available in S3 may lead to some confusion 🙂
