如何使用ImgUr npm包将图像添加到相册

问题描述 投票:0回答:1

我正在使用 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);
}

我该怎么做?

javascript typescript imgur
1个回答
0
投票

您必须包含 album 参数并使用 albumHash。

const response = await client.upload({
            album: '<ALBUMHASH>',
            image: file,
            type: 'stream',
        });
© www.soinside.com 2019 - 2024. All rights reserved.