accessing images from s3 in case insensitive way accessing images from s3 in case insensitive way express express

accessing images from s3 in case insensitive way


No, filenames on S3 are case sensitive. Presumably this is a restriction of the underlying linux/unix file system.

I always recommend to people to upload only lowercase filenames.


It should also be noted that S3 is meant to be accessed by HTTP(S). URLs in HTTP are case-sensitive. Servers which allow accessing URLs in a case-insensitive manner are broken because they possibly pollute caches. The files image.jpg, Image.jpg, IMAGE.JPG might all point to the same file, but a cache wouldn't know and load the same file multiple times. Same for a web browser. If you refer to the same image twice on the page, once as image.jpg and once as Image.jpg, the browser would load the image twice. It therefore does not make any sense to demand that S3 should be case-insensitive. Instead stick to what the RFCs about URLs and HTTP say and fix your website.

BTW whether the underlying object store is implemented on POSIX (Unix, Linux) or Windows does not matter for this topic, it's about the HTTP and URL specs (RFCs).


AWS has introduced lambda edge Now.You can point the domain(hostname of s3 which you are using) to cloudfront, configure your s3 bucket as the backend and attach a lambda edge function to the cloudfront.

Select viewer request event to trigger to the lambda function.The below nodejs code in lambda will convert all the requests received by cloudfront to lowercase and pass it to the backend s3 bucket.The below code worked for me.

exports.handler = (event, context, callback) => {    // TODO implement   const request = event.Records[0].cf.request;   console.log (request)   request.uri = request.uri.toLowerCase()   console.log (request.uri)   callback(null, request)};

The workflow is like below.

Request(mixedcase uri) --> cloudfront --> (Lambda function which will change uri to lower case) --> s3(the uri will be lowercase once request is received )