Can I update an existing Amazon S3 object header properties? - amazon-s3

I have a problem of Content-Type empty for video files and wanted to update those objects with Content-Type: video/** based on extension of the file. But when i am using the put method for same key/bucket with content-type it is being overridden with '0' content-length.
Can I update an existing Amazon S3 object? link says
put will override the file s3 object which doesn't serve my purpose.
Note: I don't want to use Java SDK. I want to use normal the Java httpput due to memory constraints of the mobile.

What you could try is to use the PUT COPY request with the same source and target.
PUT /yourvideo.flv HTTP/1.1
Host: bucket.s3.amazonaws.com
Date: Wed, 28 Oct 2009 22:32:00 GMT
x-amz-copy-source: /bucket/yourvideo.flv
Authorization: AWS AKIAIOSFODNN7EXAMPLE:0RQf4/cRonhpaBX5sCYVf1bNRuU=
Apparently python boto modifies metadata this way
Yes, I can confirm, copy is working:
PUT /test/123.png HTTP/1.1\r\n
Host: yourbucket.s3.amazonaws.com\r\n
Accept-Encoding: identity\r\n
Content-Length: 0\r\n
x-amz-storage-class: STANDARD\r\n
x-amz-copy-source: yourbucket/test/123.png\r\n
Date: Fri, 11 Jan 2013 15:16:48 GMT\r\n
Content-Type: image/gif\r\n # this is the content-type set
Authorization: AWS AKXXXXXDDRXXXXXX63CA:RcktkZ9nPwsXXXXXd+KXXXXXY=\r\n
x-amz-metadata-directive: REPLACE\r\n
\r\n
S3 Reply:
HTTP/1.1 200 OK
x-amz-id-2: Vf1bRJd+e4ru0y73GB0Ra0xYB2vv6GLWYKsHAC4AzE+a8uZB56Xy8+YTDkJ0/wfN
x-amz-request-id: C0E6A2823F3FB3E9
Date: Fri, 11 Jan 2013 15:16:49 GMT
Content-Type: application/xml
Content-Length: 234
Server: AmazonS3
Verification:
HEAD /test/123.png HTTP/1.1\r\n
Host: yourbucket.s3.amazonaws.com\r\n
Accept-Encoding: identity\r\n
Date: Fri, 11 Jan 2013 15:25:23 GMT\r\n
Content-Length: 0\r\n
Authorization: AWS AXXXIXXXXMDDXXXXX7XXXCA :HoZ4Woxxw6SWlxxxx000Rxxm8ODQ=\r\n
\r\n
S3 replies with the correct content-type ( the one I set wrongly to image/gif instead of image/png )
HTTP/1.1 200 OK
x-amz-id-2: 7Ut6sdm6i+1h7Di5UrB4v9Sn3mVCNjyDnkb4rm1jGzN6wBTgDT2/yCSHdrKG12Jd
x-amz-request-id: 38A1F6EC6ECD1D2D
Date: Fri, 11 Jan 2013 15:25:24 GMT
Last-Modified: Fri, 11 Jan 2013 15:25:24 GMT
ETag: "c09fad0faf4e6bb1148670af78b6de41"
Accept-Ranges: bytes
Content-Type: image/gif
Content-Length: 122311
Server: AmazonS3

Related

Apache + File on mounted folder = Corrupted file

We migrated our LAMP Ubuntu 16.04 (Apache 2.4.7) to a new one with Ubuntu 20.04 (Apache 2.4.41).
Both with a drive mounted on /var/www/intranet/onyar.
With the new one, if I download a file from this mounted drive it's corrupted. With the old one it works. If I download with the old server it's ok. If I access via samba it's ok.
http://newserver/intranet/onyar/test.xls => CORRUPTED
http://oldserver/intranet/onyar/test.xls => OK
\\newserver\root\var\www\intranet\onyar\test.xls => OK
So it seems a problem between Apache and mounted drive? If I try it with a file outside mounted drive (http://newserver/intranet/test.xls) it works OK.
I tested it with txt, office type and PDF files, all corrupted. HTML files works!
I put a simple 'test.txt' file with the string 'hola' inside and I open it with 'http://newserver/intranet/onyar/test.txt' the browser give me this:
Last-Modified: Thu, 12 Nov 2020 09:38:46 GMT
ETag: "4-5b3e5adb1be88"
Accept-Ranges: bytes
Content-Length: 4
Cache-Control: max-age=1209600
Expires: Thu, 26 Nov 2020 09:40:37 GMT
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/plain
holad_ip = dnsResolve(host);
if (isInNet(resolved_ip, "127.0.0.1", "255.255.255.255") || isInNet(resolved_ip, "172.16.0
In fact, if i Ctrl+F5 the string after hola (d_ip = ...) changes sometimes:
Last-Modified: Thu, 12 Nov 2020 09:38:46 GMT
ETag: "4-5b3e5adb1be88"
Accept-Ranges: bytes
Content-Length: 4
Cache-Control: max-age=1209600
Expires: Thu, 26 Nov 2020 09:57:01 GMT
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/plain
holar.</p>
<hr>
<address>Apache/2.4.41 (Ubuntu) Server at 10.80.160.178 Port 80</address>
</body></html>
p>The document h
Last-Modified: Thu, 12 Nov 2020 09:38:46 GMT
ETag: "4-5b3e5adb1be88"
Accept-Ranges: bytes
Content-Length: 4
Cache-Control: max-age=1209600
Expires: Thu, 26 Nov 2020 09:57:01 GMT
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/plain
holaIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document ha
These endings seems to be from other files! Like Apache don't know when is the file ending and puts there some other stuff...
Reference:
fstab: //onyar/dades /var/www/intranet/onyar cifs credentials=/root/.smbcredentials,file_mode=0775,dir_mode=0775,auto 0 0
It seems that I'm affected by this bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=900821
For me the solution is putting this in /etc/apache2/apache2.conf:
<Directory "/var/www/intranet/onyar">
EnableMMAP Off
</Directory>

Why can't googlebot fetch my JavaScript file?

https://api-staging-weld.freetls.fastly.net/scripts/customdomain_weld.19f3e9ec.js
The error I get in Google Search Console is Temporarily unreachable with no further explanation. I think it's something with my http headers but can't figure out which one. Here they are:
accept-ranges: bytes
access-control-allow-origin: *
age: 4905
cache-control: public, max-age=31536000
content-encoding: gzip
content-length: 29990
content-type: application/javascript; charset=UTF-8
date: Fri, 20 Apr 2018 12:46:37 GMT
etag: W/"1a018-162e269bfe0"
last-modified: Fri, 20 Apr 2018 09:36:44 GMT
server: Cowboy
status: 200
vary: Accept-Encoding
via: 1.1 vegur
via: 1.1 varnish
x-cache: HIT
x-cache-hits: 1
x-powered-by: Express
x-served-by: cache-bma7030-BMA
x-timer: S1524228398.925110,VS0,VE6
What's wrong or what am i Missing?

CORS issues with CloudFront and S3

Some of our users are getting this error in the browser consoles:
XMLHttpRequest cannot load https://d2ynz9y5qgba7.cloudfront.net/icons/instagram.svg.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'https://www.weld.io'; is therefore not allowed access.
These are the current headers:
Accept-Ranges: bytes
Access-Control-Allow-Methods: GET
Access-Control-Allow-Origin: *
Age: 21038
Content-Length: 1086
Content-Type: image/svg+xml
Date: Wed, 23 Mar 2016 10:00:12 GMT
Etag: "5cc3b790e15d7736b95880001521630b"
Last-Modified: Wed, 18 Mar 2015 10:20:32 GMT
Server: AmazonS3
Via: 1.1 8cdc69e06e564b9aef153cf0b52204b0.cloudfront.net (CloudFront)
X-Amz-Cf-Id: 0lD_0czYTm6i5f7RlURkG2dcQx_B252LC2GOu98anzHH1k1eaz2lmg==
X-Cache: Hit from cloudfront
As you can see, Access-Control-Allow-Origin is indeed present.
We are also "whitelisting" Origin on CloudFront.
What could be the cause of this issue?

Why does the web server sent the file instead of a 304 http: not modified?

My browser send to the server the following request:
Host: www.imprimante.be
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: */*
Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
If-Modified-Since: Fri, 29 May 2015 14:22:44 GMT
If-None-Match: "90-5173935ad3a1a-gzip"
Referer: http://www.imprimante.be/premier-avis-gratuit/
Cookie: <hidden>
Connection: keep-alive
The url used is http://www.imprimante.be/wp-content/themes/mch_imprimante/js/theme.min.js? (note: www.imprimante.be is not accessible trough wlan yet)
And the server send me the file with this (status 200) http header:
Accept-Ranges: bytes
Connection: Keep-Alive
Content-Encoding: gzip
Content-Length: 137
Content-Type: application/javascript
Date: Wed, 03 Jun 2015 07:18:03 GMT
Etag: "90-5173935ad3a1a-gzip"
Keep-Alive: timeout=5, max=99
Last-Modified: Fri, 29 May 2015 14:22:44 GMT
Server: Apache/2.4.10 (Debian)
Vary: Accept-Encoding
As you might notice (Last-Modified: Fri, 29 May 2015 14:22:44 GMT) the file hasn't been modified since the last request.
So I don't get why the response isn't a 304 status: not modified.
I'd really like to know why the caching of this files (and some others) doesn't work as I expect it.
It is bug in Apache. Turn off mod_deflate.

How to configure Apache to send gzipped and chunked encoded response for static content?

For the purpose of unit testing, I want to configure Apache to gzip a static file and then chunk encode it and send it as a response. I tried following so far:
# Created a file httpd-deflate.conf
# Set to gzip all output
SetOutputFilter DEFLATE
#set compression level
DeflateCompressionLevel 9
# Deflate in chunks
DeflateBufferSize 100
Included this file in httpd.conf
Include httpd-deflate.conf
Send request as follows:
GET / HTTP/1.1
Host: test-server
Accept-Encoding: gzip
Connection: Keep-Alive
Got following response:
HTTP/1.1 200 OK
Date: Wed, 05 Nov 2014 19:24:23 GMT
Server: Apache/2.2.15 (Scientific Linux)
Last-Modified: Wed, 05 Nov 2014 18:17:21 GMT
ETag: "5e28c-5df-5072097390e40"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 1186
Connection: close
Content-Type: text/html; charset=UTF-8
<binary-data>
Is there a way by which Apache can start sending the gziped data in chunked format. I thought DeflateBufferSize can help me do that. However, no luck so far.
Any suggestions?
Thanks.