houdini/app/javascript/common/activestorage.ts
2020-09-01 21:32:32 -05:00

16 lines
No EOL
483 B
TypeScript

// License: LGPL-3.0-or-later
import { DirectUpload, Blob } from '@rails/activestorage';
export function uploadFile(controllerUrl: string, file: File): Promise<Blob> {
const duPromise = new Promise<Blob>((resolve, reject) => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
const du = new DirectUpload(file, controllerUrl);
du.create((error, result) => {
if (error) { reject(error); }
if (result) { resolve(result); }
});
});
return duPromise;
}