fix: file size in local operations

This commit is contained in:
Dan Ribbens
2021-02-09 15:12:29 -05:00
parent 9d51af3bf8
commit 0feb7b7379
3 changed files with 8 additions and 1 deletions

View File

@@ -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;
});
});

View File

@@ -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,
};
}

View File

@@ -46,4 +46,5 @@ export type File = {
data: Buffer
mimetype: string
name: string
size: number
}