const { PassThrough } = require("stream");
const fetch = require("node-fetch");
const FormData = require("form-data");
//uploads an image to imgur and returns a link
async function uploadImage(image) {
const stream = await image.getStream();
const form = new FormData();
form.append("image", stream, {
contentType: stream.contentType,
filename: stream.filename,
`This image can also be (temporarily) viewed at: ${image.cloudUrl} and ${image.localUrl}`
const response = await fetch("https://api.imgur.com/3/image", {
//pipe through a passthrough stream, workarround for a node-fetch bug involving form-data streams without content length set.
body: form.pipe(new PassThrough()),
Authorization: "Client-ID <YOUR_CLIENT_ID>",
throw new Error(response.statusText);
const { data } = await response.json();