Skip to content

Commit 1ac9cf8

Browse files
committed
✨ feat(api): getFileBlob
1 parent 4c004d7 commit 1ac9cf8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/api.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,28 @@ export async function getFile(path: string): Promise<any> {
335335
});
336336
}
337337

338+
339+
/**
340+
* fetchPost will secretly convert data into json, this func merely return Blob
341+
* @param endpoint
342+
* @returns
343+
*/
344+
export const getFileBlob = async (path: string): Promise<Blob | null> => {
345+
const endpoint = '/api/file/getFile'
346+
let response = await fetch(endpoint, {
347+
method: 'POST',
348+
body: JSON.stringify({
349+
path: path
350+
})
351+
});
352+
if (!response.ok) {
353+
return null;
354+
}
355+
let data = await response.blob();
356+
return data;
357+
}
358+
359+
338360
export async function putFile(path: string, isDir: boolean, file: any) {
339361
let form = new FormData();
340362
form.append('path', path);

0 commit comments

Comments
 (0)