我正在嘗試在我的 API 上創建一個端點,我可以在其中按需調整 S3 中的影像大小。我已經讓它作業了,但是回傳呼整大小的影像大約需要 7 秒,而在不調整大小的情況下回傳影像大約需要 800 毫秒。我是處理影像的新手,并決定使用Sharp包,因為它看起來很簡單。我想知道是否有人可以告訴我我做錯了什么?或者有什么方法可以加快速度?還是尖銳只是慢?
我的代碼是:
const getCommand = new GetObjectCommand({
Bucket: 'mybucket',
Key: 'myfile'
});
const getResponse = await s3Client.send(getCommand);
// Set response headers
response.set('Content-Length', getResponse.ContentLength);
response.set('Content-Type', getResponse.ContentType);
response.statusCode = 200;
// Stream response
getResponse.Body.pipe(response);
// GetResponse.Body.pipe(sharp().resize(40, 40)).pipe(response)
提前致謝!
uj5u.com熱心網友回復:
嘗試洗掉Content-Length標頭:
response.set('Content-Length', getResponse.ContentLength);
當我測驗您的代碼時,這提高了性能。
檢查您是否觀察到相同的改進。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/425477.html
標籤:javascript 节点.js 亚马逊-s3 图像处理 锋利的
上一篇:如何比較兩個物件的兩點
