minio-js
minio-js copied to clipboard
How to match signature when using pre-signed URL?
I'm following the tutorial on uploading files to S3 storage. I'm running a local instance of min.io in a Docker container. My application is running a simple express.js server with an endpoint that generates the URL:
server.get("/presignedUrl", (req, res) => {
client.presignedPutObject(
"mybucket", // bucket name
req.query.objectName, // file name
60 * 60, // expires in 60 minutes
(err, url) => {
if (err) throw err;
res.end(url);
}
);
});
I'm using this endpoint inside a React app, which is supposed to upload the file into the S3 bucket. I'm using the generated URL with a fetch function to pass the file as a body using the PUT method:
async function handleFileUpload() {
try {
const presignedUrl = await fetch(
`http://localhost:4000/presignedUrl?objectName=${files[0].name}`
);
const url = await presignedUrl.text();
const uploadFile = await fetch(url, {
method: "PUT",
body: files[0],
});
} catch (error) {
setError(error.message);
}
}
The error I'm getting back is that The request signature we calculated does not match the signature you provided. Check your key and signing method. I'm pretty new to S3, not sure if I need to prepare some special access policy or adjust anything else in my storage settings. My access and secret keys are matching whatever the server-side connection is using, my test user can read and write into the bucket. Not sure what I'm doing wrong here. Is there a way to validate the pre-signed URLs before I use them (like a dry-run test)?
Please check the headers like host and and any other headers that might interfere the s3 signature calculation
Also please confirm the minio-js version and minio server version.
Also please double check : const url = await presignedUrl.text();
https://github.com/minio/minio-js/pull/968 there was a fix related to this sometime back
No activity. closing this.