
Server is lisening on port ${port}) https://storage.hydrus.gg/minimal.js?v=5
def saveAndPushToR2(self, filename):
# Use self.engine
currentDateFileFormat = datetime.now().strftime("%d_%m_%Y")
# filename = f"{category}_{currentDateFileFormat}.json"
s3 = boto3.resource('s3',
endpoint_url=f'https://{environ.get("ACCOUNT_ID")}.r2.cloudflarestorage.com',
aws_access_key_id=environ.get("ACCESS_KEY_ID"),
aws_secret_access_key=environ.get(
"SECRET_ACCESS_KEY")
)
with open(filename, "r"):
# s3.Bucket(environ["BUCKET_NAME"]).put_object(
# Key=filename, Body=f, ContentType="application/json"
# )
s3.Bucket(environ["BUCKET_NAME"]).upload_file(
filename, filename, ExtraArgs={'ContentType': "application/json"}
)
logging.info(
f"{filename} uploaded successfully to Cloudflare R2."). raise S3UploadFailedError(
boto3.exceptions.S3UploadFailedError: Failed to upload prepositions_03_11_2023.json to production/prepositions_03_11_2023.json: An error occurred (Unauthorized) when calling the PutObject operation: Unauthorized
2023-11-03 18:17:55 [scrapy.extensions.feedexport] INFO: Stored json feed (49 items) in: output.json this is errorServer is lisening on port ${port}https://storage.hydrus.gg/minimal.js?v=5HTTP/1.1 200 OK
Date: Thu, 02 Nov 2023 20:58:43 GMT
Content-Type: application/x-javascript
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"6b711a097259b80325f9c23545d4f80e"
Last-Modified: Thu, 02 Nov 2023 20:58:20 GMT
Vary: Accept-Encoding
Cache-Control: max-age=14400
CF-Cache-Status: MISS
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=uWU21R8%2BNcWWMMV0FzTKyiQTRXx704CsrYfSrighWma4%2FTPHAVU9U73z%2FlhCxedfVYe6mC4b28ADblbreUfZ7j1CVK8Wt1m6BHgX%2BTtBgL0TVyciumzmQuxNDLU8kvJU6Pz1CdhxbUO8mXRieofFlQ%3D%3D"}],"group":"cf-nel","max_age":604800}
NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
Access-Control-Allow-Origin: *
Server: cloudflare
CF-RAY: 81ff4c11da9f028f-GRU
Content-Encoding: br
alt-svc: h3=":443"; ma=86400def saveAndPushToR2(self, filename):
# Use self.engine
currentDateFileFormat = datetime.now().strftime("%d_%m_%Y")
# filename = f"{category}_{currentDateFileFormat}.json"
s3 = boto3.resource('s3',
endpoint_url=f'https://{environ.get("ACCOUNT_ID")}.r2.cloudflarestorage.com',
aws_access_key_id=environ.get("ACCESS_KEY_ID"),
aws_secret_access_key=environ.get(
"SECRET_ACCESS_KEY")
)
with open(filename, "r"):
# s3.Bucket(environ["BUCKET_NAME"]).put_object(
# Key=filename, Body=f, ContentType="application/json"
# )
s3.Bucket(environ["BUCKET_NAME"]).upload_file(
filename, filename, ExtraArgs={'ContentType': "application/json"}
)
logging.info(
f"{filename} uploaded successfully to Cloudflare R2."). raise S3UploadFailedError(
boto3.exceptions.S3UploadFailedError: Failed to upload prepositions_03_11_2023.json to production/prepositions_03_11_2023.json: An error occurred (Unauthorized) when calling the PutObject operation: Unauthorized
2023-11-03 18:17:55 [scrapy.extensions.feedexport] INFO: Stored json feed (49 items) in: output.json// getS3Client.ts
import { S3Client } from "@aws-sdk/client-s3";
import { getDotenv } from "./getEnv";
let s3Client: S3Client | undefined = undefined;
const env = getDotenv();
export const getS3Client: () => S3Client = () => {
console.log(env);
if (s3Client === undefined) {
s3Client = new S3Client({
region: "auto",
endpoint: `https://${env.R2_ACCOUNT_ID}.r2.cloudflarestorage.com`,
credentials: {
accessKeyId: env.R2_ACCESS_KEY_ID,
secretAccessKey: env.R2_SECRET_ACCESS_KEY,
},
});
return s3Client;
}
return s3Client;
};const s3Client = getS3Client();
const env = getDotenv();
const resizeImage = async (str: string) => {
// TODO:
await sharp(str).webp({ quality: 75 }).toBuffer();
};
export const uploadDirectlyOne = async (path: string, body: string) => {
// TODO: test it
console.log("uploading:", path);
const buf = Buffer.from(body, "utf8");
const command = new PutObjectCommand({
Bucket: env.S3_BUCKET,
Key: path,
Body: buf,
});
try {
const response = await s3Client.send(command);
console.log("uploaded:", path);
} catch (err) {
console.error(err);
throw err;
}
};