@self.id/image-utils
Version:
Image utilities for Self.ID profiles
16 lines (15 loc) • 472 B
JavaScript
/**
* Upload the `blob` file to the given IPFS server `url`, using the optionally given `fileName`.
*/ export async function uploadFile(url, blob, fileName) {
const body = new FormData();
body.append('path', blob, fileName);
const res = await fetch(`${url}/add`, {
method: 'POST',
body
});
if (res.ok) {
const { Hash } = await res.json();
return Hash;
}
throw new Error(`Upload failed: ${res.statusText}`);
}