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);
const response = await fetch("https://upload.gyazo.com/api/upload", {
method: "POST",
body,
});
if (!response.ok) {
throw new Error("Failed to upload image to Gyazo");
}
const data = await response.json();
if (data.url && data.url.length > 0 && data.url.startsWith('https://i.gyazo.com/')) {
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;
}