所以我做了一個Meme Gallery應用程式。 這里是鏈接:https://meme-gallery-web-app.netlify.app/
你可以通過鏈接上傳圖片。首先,我試圖檢查提交的URL是否有jpg/png擴展名,以便我可以處理它(無論是否上傳)。 這就是為什么我試圖實作影像型別包。但它給了我上述的錯誤。 以下是我實作的代碼。
const https = require("https") 。
const imageType = require("image-type") 。
const imageModel = require("./models/models.js") 。
var date = new Date();
var currentDate = date.toLocaleDateString();
const submitLink = async(req, res)=> {
const { url } = req.body;
https.get(url, (response) =>/span> {
response.on("readable", () =>/span> {
const chunk = response.read(imageType.minimumBytes) 。
response.destroy()。
console.log(imageType(chunk))。
});
});
};
在提交鏈接后,我得到了以下錯誤:
TypeError。預期輸入引數是的型別Uint。 title class_">Uint8Array或Buffer或 ArrayBuffer。得到物件
所以我檢查后發現,變數chunk是一個物件,而不是Uint8Array或Buffer。這是為什么呢?如何解決這個問題呢?
uj5u.com熱心網友回復:
我認為你應該讀取這些塊,將它們連接起來,然后將產生的緩沖區傳遞給imageType庫:
https.get(url, response => //span> {
const chunks = [];
response.on("data", (chunk) => {
chunks.push(chunk)。
})
response.on("end", ( ) => {
const resultBuffer = Buffer.concat(chunks)。
console.log("image type is", imageType(resultBuffer ))。
})
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/310199.html
標籤:
上一篇:錯誤。無效的鉤子呼叫。鉤子只能在函陣列件的主體內呼叫。[我仍然在使用函陣列件]
下一篇:在一個攔截的中間件中獲取快件引數
