我正在使用 ImgUr NPM 库 上传我的图像。 之后我想将上传的图像添加到相册中,说“HelloWorld”。
这是我的代码:
export async function uploadToImgUr(files: Buffer[]): Promise<string[]> {
const uploadPromises = files.map(async (file) => {
const formData = new FormData();
formData.append('image', file);
const response = await client.upload({
image: file,
type: 'stream',
});
// Add the uploaded image to the album, this is my guess, but not working
const resp = await client.getAlbum(brand);
resp.data.images.push(response.data);
return response.data.link;
});
return Promise.all(uploadPromises);
}
我该怎么做?
您必须包含 album 参数并使用 albumHash。
const response = await client.upload({
album: '<ALBUMHASH>',
image: file,
type: 'stream',
});