i'm trying to upload a file through Postman to my bucket. Im usign a post request so on my nodejs backend i'm generating a presigned post url, by using this function on aws sdk
Url() {
const suffix = `${(0, uuid_1.v4)()}`;
const extension = path_1.default.basename(this.fileName);
const params = {
Bucket: constants_1.BUCKET,
Fields: {
Key: `${this.pathToSave}/${suffix}${extension}`,
"Content-Type": "image/jpeg"
},
Conditions: [
["content-length-range", 0.1, 200000000],
["eq", "$x-amz-meta-postid", this.postId],
["eq", "$Content-Type", "image/jpeg"]
],
Expires: 180
};
return new Promise((resolve, reject) => {
S3.createPresignedPost(params, function (err, data) {
if (err) {
reject(err);
return;
}
resolve(data);
});
});
}
This is how i'm making the request through postman
The problem is that when i send the request i'm gettin a 400 Bad Request error. I have read all the aws documentation and searched online, but i'm not understanding how to solve this problem.
CodePudding user response:
In your conditions change:
["content-length-range", 0.1, 200000000] to ["content-length-range", 1, 200000000]
My code that works:
const params = {
Bucket: "{bucket_name}",
Fields: {
Key: `test.jpg`,
"Content-Type": "image/jpeg"
},
Conditions: [
["content-length-range", 1, 2000000000],
["eq", "$x-amz-meta-postid", "some-post-id"],
["eq", "$Content-Type", "image/jpeg"]
],
Expires: 380
};
s3.createPresignedPost(params, function(err, data) {
if (err) {
console.error('Presigning post data encountered an error', err);
} else {
console.log('The post data is', data);
}
});
Request to postman: