fix: 预览URL添加API key参数
This commit is contained in:
@@ -24,7 +24,6 @@ export async function POST(request: NextRequest) {
|
|||||||
const buffer = await file.arrayBuffer();
|
const buffer = await file.arrayBuffer();
|
||||||
imageBuffer = Buffer.from(buffer);
|
imageBuffer = Buffer.from(buffer);
|
||||||
|
|
||||||
// 压缩图片
|
|
||||||
const image = sharp(imageBuffer);
|
const image = sharp(imageBuffer);
|
||||||
const metadata = await image.metadata();
|
const metadata = await image.metadata();
|
||||||
|
|
||||||
@@ -56,7 +55,6 @@ export async function POST(request: NextRequest) {
|
|||||||
.toBuffer() as any;
|
.toBuffer() as any;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 上传到 my_oss
|
|
||||||
const formData2 = new FormData();
|
const formData2 = new FormData();
|
||||||
const uint8Array = new Uint8Array(imageBuffer);
|
const uint8Array = new Uint8Array(imageBuffer);
|
||||||
const blob = new Blob([uint8Array], { type: 'image/jpeg' });
|
const blob = new Blob([uint8Array], { type: 'image/jpeg' });
|
||||||
@@ -78,8 +76,7 @@ export async function POST(request: NextRequest) {
|
|||||||
|
|
||||||
const fileData = await uploadRes.json();
|
const fileData = await uploadRes.json();
|
||||||
|
|
||||||
// 返回 my_oss 的访问URL
|
const url = `${OSS_URL}/api/files/${fileData.fileKey}/preview?key=${API_KEY}`;
|
||||||
const url = `${OSS_URL}/api/files/${fileData.fileKey}/preview`;
|
|
||||||
return NextResponse.json({ url, fileKey: fileData.fileKey });
|
return NextResponse.json({ url, fileKey: fileData.fileKey });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Upload error:', error);
|
console.error('Upload error:', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user