mirror of
https://github.com/MarSeventh/CloudFlare-ImgBed.git
synced 2026-01-31 09:03:19 +08:00
fix: use actual R2 file size instead of client-side size
This commit is contained in:
@@ -227,12 +227,16 @@ async function uploadFileToCloudflareR2(context, fullId, metadata, returnLink) {
|
||||
|
||||
const R2DataBase = env.img_r2;
|
||||
|
||||
// 写入R2数据库
|
||||
await R2DataBase.put(fullId, formdata.get('file'));
|
||||
// 写入R2数据库,获取实际存储大小
|
||||
const r2Object = await R2DataBase.put(fullId, formdata.get('file'));
|
||||
|
||||
// 更新metadata
|
||||
metadata.Channel = "CloudflareR2";
|
||||
metadata.ChannelName = r2Channel.name || "R2_env";
|
||||
// 使用 R2 返回的实际文件大小
|
||||
if (r2Object && r2Object.size) {
|
||||
metadata.FileSize = (r2Object.size / 1024 / 1024).toFixed(2);
|
||||
}
|
||||
|
||||
// 图像审查,采用R2的publicUrl
|
||||
const R2PublicUrl = r2Channel.publicUrl;
|
||||
|
||||
Reference in New Issue
Block a user