diff --git a/packages/strapi-plugin-upload/admin/src/utils/formatBytes.js b/packages/strapi-plugin-upload/admin/src/utils/formatBytes.js index 592990e7fd..8d9a8b2447 100644 --- a/packages/strapi-plugin-upload/admin/src/utils/formatBytes.js +++ b/packages/strapi-plugin-upload/admin/src/utils/formatBytes.js @@ -1,5 +1,7 @@ // Source: https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript -function formatBytes(bytes, decimals) { +function formatBytes(receivedBytes, decimals) { + const bytes = receivedBytes * 1000; + if (bytes < 1) { return '0B'; } diff --git a/packages/strapi-plugin-upload/admin/src/utils/tests/formatBytes.test.js b/packages/strapi-plugin-upload/admin/src/utils/tests/formatBytes.test.js index 65fa157191..0759d7a34c 100644 --- a/packages/strapi-plugin-upload/admin/src/utils/tests/formatBytes.test.js +++ b/packages/strapi-plugin-upload/admin/src/utils/tests/formatBytes.test.js @@ -7,27 +7,27 @@ describe('UPLOAD | components | EditForm | utils', () => { }); it('should return 0B if less than 1 bytes is passed', () => { - expect(formatBytes(0.9)).toEqual('0B'); + expect(formatBytes(0.9)).toEqual('900B'); }); it('should return 1KB if 1024 Bytes is passed', () => { - expect(formatBytes(1024)).toEqual('1KB'); + expect(formatBytes(1024)).toEqual('1000KB'); }); it("should return 1KB if '1024' Bytes is passed", () => { - expect(formatBytes('1024')).toEqual('1KB'); + expect(formatBytes('1024')).toEqual('1000KB'); }); it('should return 1.21KB if 1034 Bytes is passed', () => { - expect(formatBytes(1234)).toEqual('1.21KB'); + expect(formatBytes(1234)).toEqual('1.18MB'); }); it('should return 1.21KB if 1034 Bytes is passed with 3 decimals', () => { - expect(formatBytes(1234, 3)).toEqual('1.205KB'); + expect(formatBytes(1234, 3)).toEqual('1.177MB'); }); it('should return 1 MB if 1.1e+6 Bytes is passed', () => { - expect(formatBytes(1100000, 0)).toEqual('1MB'); + expect(formatBytes(1100000, 0)).toEqual('1GB'); }); }); });