convex
Version:
Client for the Convex Cloud
23 lines (22 loc) • 742 B
JavaScript
;
import { useMutationGeneric } from "../react/index.js";
export function useUploadGeneric(name) {
const generateUploadUrl = useMutationGeneric(name);
return async (file) => {
const postUrl = await generateUploadUrl();
const res = await fetch(postUrl, {
method: "POST",
headers: { "Content-Type": file.type },
body: file
});
if (res.status === 200) {
const { storageId } = await res.json();
return storageId;
} else {
const { code, message } = await res.json();
console.error(`${res.status} ${res.statusText}: ${code}: ${message}`);
throw new Error(`${res.status} ${res.statusText}: ${code}: ${message}`);
}
};
}
//# sourceMappingURL=use_upload.js.map