You don’t need to encode the object key before running the PutObject command, it should just work.
The URL on the dash in the Object view is encoded on purpose, so that one can just copy and paste it anywhere without having to worry about encoding the params.
Here is a snippet of the code I ran in javascript as a reference, please let me know how it goes.
import {
S3Client,
PutObjectCommand,
} from "@aws-sdk/client-s3";
import * as path from "path";
import * as fs from 'fs';
const S3 = new S3Client({
region: "auto",
endpoint: `https://<ACCOUNT_ID>.r2.cloudflarestorage.com/`,
credentials: {
accessKeyId: "<ACCESS_KEY_ID>",
secretAccessKey: "<ACCESS_KEY_SECRET>",
},
});
const file = "테스트.png"; // Path to and name of object. For example '../myFiles/index.js', for me the image is in the same folder as this javascript file.
const fileStream = fs.createReadStream(file);
const fileName = path.basename(file)
// Set the parameters
const uploadParams = {
Bucket: "<BUCKET_NAME>",
Key: fileName,
Body: fileStream,
ContentType: 'image/png' // you can omit this
};
// Upload file to specified bucket.
const run = async () => {
try {
const data = await S3.send(new PutObjectCommand(uploadParams));
console.log("Success", data);
return data;
} catch (err) {
console.log("Error", err);
}
};
run();