我有这个代码是应该转换为缓冲区流的URL,所以我可以在我的API请求中使用它,但得到了错误
router.get("/", async (req, res) => {
let imageUrl = 'https://oaidalleapiprodscus.blob.core.windows.net/private/org-yeajcMsnWR7hOKZLzEiwGQ5o/user-jDFXxFJWLVyxyKditQpOgSYF/img-KQoVwCMTB13cU2wZeVEzAajX.png?st=2023-04-26T05%3A41%3A25Z&se=2023-04-26T07%3A41%3A25Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-04-26T06%3A21%3A17Z&ske=2023-04-27T06%3A21%3A17Z&sks=b&skv=2021-08-06&sig=VUHDc/GxPPKdbzGU3deNsAiDGaHOHcr6CixnCdpSpeE%3D';
try {
const response = await axios.get(imageUrl, { responseType: 'arraybuffer' });
const bufferStream = new stream.PassThrough();
bufferStream.end(Buffer.from(response.data, 'binary'));
const imageVariationResponse = await openai.createImageVariation(
bufferStream,
1,
"256x256"
);
const result = imageVariationResponse.data.data[0].url;
console.log('result :', result);
res.json({ result: result });
} catch (error) {
console.error(error);
res.status(500).json({ error: error });
}
});
请求失败,状态代码为400
1条答案
按热度按时间4nkexdtk1#
对于任何人寻找一个解决方案,这里是我更新的完整代码