haltbill
04/07/2023, 6:31 AMKuyumee
04/07/2023, 8:04 AMnpx aws-sdk-js-codemod -t v2-to-v3 index.js
, it stops working.
v2:
js
require("dotenv").config();
const AWS = require("aws-sdk");
const fs = require("fs");
const s3 = new AWS.S3({
endpoint: process.env.R2_ENDPOINT,
accessKeyId: process.env.R2_ACCESS_KEY,
secretAccessKey: process.env.R2_SECRET_KEY,
region: process.env.R2_REGION,
});
(async () => {
const result = await s3
.upload({
Bucket: process.env.R2_BUCKET_NAME,
Key: "IMG20221229195709.jpg",
Body: fs.createReadStream("IMG20221229195709.jpg"),
})
.promise();
console.log(`File uploaded successfully. ${result.Location}`);
})();
v3 (not working):
js
require("dotenv").config();
const { Upload } = require("@aws-sdk/lib-storage");
const { S3 } = require("@aws-sdk/client-s3");
const fs = require("fs");
const s3 = new S3({
endpoint: process.env.R2_ENDPOINT,
accessKeyId: process.env.R2_ACCESS_KEY,
secretAccessKey: process.env.R2_SECRET_KEY,
region: process.env.R2_REGION,
});
(async () => {
const result = await new Upload({
client: s3,
params: {
Bucket: process.env.R2_BUCKET_NAME,
Key: "IMG20221229195709.jpg",
Body: fs.createReadStream("IMG20221229195709.jpg"),
},
}).done();
console.log(`File uploaded successfully. ${result.Location}`);
})();
Walshy | Pages
04/07/2023, 1:29 PMTimothy
04/07/2023, 9:38 PMKarew
04/07/2023, 10:09 PMTimothy
04/07/2023, 10:11 PMKarew
04/07/2023, 10:15 PMUnsmart | Tech debt
04/07/2023, 10:17 PMKarew
04/07/2023, 10:19 PMHardAtWork
04/07/2023, 10:25 PMRyuntai
04/07/2023, 11:46 PMDJPaul
04/07/2023, 11:48 PMSkye
04/07/2023, 11:51 PMSkye
04/07/2023, 11:51 PMUnsmart | Tech debt
04/07/2023, 11:59 PMSkye
04/08/2023, 12:00 AMlandscapepainter
04/08/2023, 2:18 AMBucket name can only contain lowercase letters (a-z), numbers (0-9), and hyphens (-)
? I was wondering if r2 follows exactly the same naming rules as s3(https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html) or has some different set of rules. Also, is there a doc for r2 naming rules?Ryuntai
04/08/2023, 3:50 AMkian
04/08/2023, 3:56 AMkian
04/08/2023, 3:56 AMRyuntai
04/08/2023, 3:58 AMRyuntai
04/08/2023, 4:00 AMRyuntai
04/08/2023, 4:00 AMMigmac
04/08/2023, 12:27 PMAccess to XMLHttpRequest at _____ from origin 'http://localhost:5174' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Should mention the preflight also returns the proper headers
I have setup the bucket CORS settings to include for the http://localhost:5174
origin, as well as the PUT
and have set the Allowed Headers to *
and also tried with Content-Type
Any suggestions as to why this isn't working and a possible way to fix it?Migmac
04/08/2023, 12:30 PMSKRRRTT
04/09/2023, 3:12 AMSKRRRTT
04/09/2023, 3:15 AMkian
04/09/2023, 3:25 AMkian
04/09/2023, 3:25 AMSKRRRTT
04/09/2023, 3:26 AM