uploadToGyazo
fileは<input type="file">でuploadしたやつ
Blobでもいけるらしい?
cURLからuploadしたときはうまくいくんだけどな……
17:40:49 ArrayBufferじゃなくてBlobを送るんだった
2022-02-04
version管理もできて便利?
code:script.js
export async function uploadToGyazo(image, accessToken, {
title,
refererURL,
description,
created,
}) {
const formData = new FormData();
formData.append('imagedata', image);
formData.append('access_token', accessToken);
if (refererURL || location?.href) formData.append('referer_url', refererURL ?? location.href);
if (title) formData.append('title', title);
if (description) formData.append('desc', description);
if (created) formData.append('created_at', created);
const res = await fetch(
{
method: 'POST',
mode: 'cors',
credentials: 'include',
body: formData,
},
);
return await res.json();
}
code:script.d.ts
export function uploadToGyazo(image: Blob, accessToken: string, options: {
title?: string;
refererURL?: string;
description?: string;
created?: number;
}): Promise<{
image_id: string;
permalink_url: string;
thumb_url: string;
url: string;
type: string;
}>;