When I try setting expiration via nodejs (code below)
import "dotenv-defaults/config";
import { PutBucketLifecycleConfigurationCommandInput } from "@aws-sdk/client-s3";
const s3Client = new S3({
endpoint: "https://sgp1.digitaloceanspaces.com",
region: "sgp1",
credentials: {
accessKeyId: process.env.ACCESS_KEY,
secretAccessKey: process.env.SPACES_SECRET
}
});
const params: PutBucketLifecycleConfigurationCommandInput = {
Bucket: "maxchat",
LifecycleConfiguration: {
Rules: [
{
Expiration: {
Days: 1,
},
Filter: {
Prefix: "oneday/",
},
Status: "Enabled",
ID: "Expiration1Days",
},
],
},
};
const run = async () => {
try {
const data = await s3Client.putBucketLifecycleConfiguration(params);
console.log("data", data);
} catch (err) {
console.log("Error", err);
}
};
run();
and I try to get my object (file) in other prefix (folder) using nodejs (code below)
// some import ...
export const params: GetObjectCommandInput = {
Bucket: "<my-space-name>",
Key: "other-perfix/<my-file>.txt",
};
// Generates the URL.
export const run = async () => {
try {
const data = await s3Client.getObject(params); // Adjustable expiration.
console.log("Contents:", data.Expiration);
return data;
} catch (err) {
console.log("Error", err);
}
};
run();
and the result (concole.log) is
Contents: {
'$metadata': {
httpStatusCode: 200,
requestId: undefined,
extendedRequestId: undefined,
cfId: undefined,
attempts: 1,
totalRetryDelay: 0
},
AcceptRanges: 'bytes',
Expiration: 'expiry-date="Tue, 06 Sep 2022 15:03:07 GMT", rule-id="Expiration1Days"',
LastModified: 2022-09-05T15:03:07.000Z,
// other log....
why my file with prefix “other-prefix” expiration with id “Expiration1Days” ?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!