fix: file size in local operations
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import payload from '../../..';
|
||||
|
||||
@@ -13,18 +14,21 @@ describe('Collections - Local', () => {
|
||||
describe('Create', () => {
|
||||
it('should allow an upload-enabled file to be created and uploaded', async () => {
|
||||
const alt = 'Alt Text Here';
|
||||
const filePath = path.resolve(__dirname, '../../../admin/assets/images/generic-block-image.svg');
|
||||
const { size } = fs.statSync(filePath);
|
||||
|
||||
const result = await payload.create({
|
||||
collection: 'media',
|
||||
data: {
|
||||
alt,
|
||||
},
|
||||
filePath: path.resolve(__dirname, '../../../admin/assets/images/generic-block-image.svg'),
|
||||
filePath,
|
||||
});
|
||||
|
||||
expect(result.id).not.toBeNull();
|
||||
expect(result.alt).toStrictEqual(alt);
|
||||
expect(result.filename).toStrictEqual('generic-block-image.svg');
|
||||
expect(result.filesize).toStrictEqual(size);
|
||||
createdMediaID = result.id;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ const getFileByPath = (filePath: string): File => {
|
||||
if (typeof filePath === 'string') {
|
||||
const data = fs.readFileSync(filePath);
|
||||
const mimetype = mime.getType(filePath);
|
||||
const { size } = fs.statSync(filePath);
|
||||
|
||||
const name = path.basename(filePath);
|
||||
|
||||
@@ -14,6 +15,7 @@ const getFileByPath = (filePath: string): File => {
|
||||
data,
|
||||
mimetype,
|
||||
name,
|
||||
size,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -46,4 +46,5 @@ export type File = {
|
||||
data: Buffer
|
||||
mimetype: string
|
||||
name: string
|
||||
size: number
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user