Uploading to Amazon S3 using a signed URL works with curl but not in javascript
The issue was the 'Content-Header' which curl was not sending. Chrome sends this header regardless of whether you add it explicitly. To get a signed url that will work with this header you need to pass headers={'Content-Type':type} to generate_url in boto.
For me the problem was I was not setting the content-type while generating presigned URL, so added that while generating presigned url
java.util.Date expiration = new java.util.Date(); long msec = expiration.getTime(); msec += 60 * 60 * 1000; // 1 hour. expiration.setTime(msec); GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest("bucket_name", "someRandomKey"); generatePresignedUrlRequest.setMethod(HttpMethod.PUT); // Default. generatePresignedUrlRequest.setExpiration(expiration); generatePresignedUrlRequest.setContentType("application/octet-stream"); URL s = s3Client.generatePresignedUrl(generatePresignedUrlRequest); System.out.println("Secure PUT URL is "+s);
And here is the curl
curl -v -X PUT \ 'generated_secure_url' \ -H 'Content-Type:application/octet-stream' \ --data-binary '@swiggy-hackathon.jpg'