Upload to Gyazo with TypeScript
code:ts
export const uploadToGyazoSingle = async (imageFile: File): Promise<string> => {
const imagedata = new Blob(imageFile, { type: imageFile.type }); const body = new FormData();
body.append("access_token", "");
body.append("imagedata", imagedata);
method: "POST",
body,
});
if (!response.ok) {
throw new Error("Failed to upload image to Gyazo");
}
const data = await response.json();
return data.url;
} else {
throw new Error("Failed to upload image to Gyazo");
}
}
export const uploadToGyazoMultiple = async (imageFiles: File[]): Promise<string[]> => {
const urls = [];
for (const imageFile of imageFiles) {
urls.push(await uploadToGyazoSingle(imageFile));
}
return urls;
}