feat: allows upload through Local API
This commit is contained in:
22
src/uploads/getFileByPath.ts
Normal file
22
src/uploads/getFileByPath.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import fs from 'fs';
|
||||
import mime from 'mime';
|
||||
import { File } from './types';
|
||||
|
||||
const getFileByPath = (filePath: string): File => {
|
||||
if (typeof filePath === 'string') {
|
||||
const data = fs.readFileSync(filePath);
|
||||
const mimetype = mime.getType(filePath);
|
||||
|
||||
const name = filePath.split('/').pop();
|
||||
|
||||
return {
|
||||
data,
|
||||
mimetype,
|
||||
name,
|
||||
};
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export default getFileByPath;
|
||||
Reference in New Issue
Block a user