+
mime.split(/[\s/]+/)[1];
+const getExtension = mime => (mime ? mime.split(/[\s/]+/)[1] : 'undefined');
export default getExtension;
diff --git a/packages/strapi-plugin-upload/admin/src/utils/getType.js b/packages/strapi-plugin-upload/admin/src/utils/getType.js
index e15571e13b..a89acc8dc0 100644
--- a/packages/strapi-plugin-upload/admin/src/utils/getType.js
+++ b/packages/strapi-plugin-upload/admin/src/utils/getType.js
@@ -1,4 +1,8 @@
const getType = mime => {
+ if (!mime) {
+ return 'file';
+ }
+
const type = mime.split(/[\s/]+/)[0];
if (type === 'image' || type === 'video') {
diff --git a/packages/strapi-plugin-upload/admin/src/utils/index.js b/packages/strapi-plugin-upload/admin/src/utils/index.js
index a6d7827cb2..33ac53eca3 100644
--- a/packages/strapi-plugin-upload/admin/src/utils/index.js
+++ b/packages/strapi-plugin-upload/admin/src/utils/index.js
@@ -11,4 +11,3 @@ export { default as getRequestUrl } from './getRequestUrl';
export { default as getTrad } from './getTrad';
export { default as getType } from './getType';
export { default as ItemTypes } from './ItemTypes';
-export { default as prefixFileUrlWithBackendUrl } from './prefixFileUrlWithBackendUrl';
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..29c5d05588 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
@@ -6,28 +6,24 @@ describe('UPLOAD | components | EditForm | utils', () => {
expect(formatBytes(0)).toEqual('0B');
});
- it('should return 0B if less than 1 bytes is passed', () => {
- expect(formatBytes(0.9)).toEqual('0B');
- });
-
- it('should return 1KB if 1024 Bytes is passed', () => {
- expect(formatBytes(1024)).toEqual('1KB');
+ it('should return 900B if 0.9 bytes is passed', () => {
+ 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 1.21KB if 1034 Bytes is passed', () => {
- expect(formatBytes(1234)).toEqual('1.21KB');
+ it('should return 1.18MB if 1034 Bytes is passed', () => {
+ 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');
+ it('should return 1.177MB if 1234 Bytes is passed with 3 decimals', () => {
+ 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');
+ it('should return 1 GB if 1.1e+6 Bytes is passed', () => {
+ expect(formatBytes(1100000, 0)).toEqual('1GB');
});
});
});
diff --git a/packages/strapi-plugin-upload/admin/src/utils/tests/getExtension.test.js b/packages/strapi-plugin-upload/admin/src/utils/tests/getExtension.test.js
index 5fd311ea73..03394310bd 100644
--- a/packages/strapi-plugin-upload/admin/src/utils/tests/getExtension.test.js
+++ b/packages/strapi-plugin-upload/admin/src/utils/tests/getExtension.test.js
@@ -1,6 +1,13 @@
import getExtension from '../getExtension';
describe('UPLOAD | utils | getExtension', () => {
+ it('should return undefined if mime does not exits', () => {
+ const mime = null;
+ const expected = 'undefined';
+
+ expect(getExtension(mime)).toEqual(expected);
+ });
+
it('should return png if mime string is image/png', () => {
const mime = 'image/png';
const expected = 'png';
diff --git a/packages/strapi-plugin-upload/admin/src/utils/tests/getType.test.js b/packages/strapi-plugin-upload/admin/src/utils/tests/getType.test.js
index 76288544d0..1e0f71853b 100644
--- a/packages/strapi-plugin-upload/admin/src/utils/tests/getType.test.js
+++ b/packages/strapi-plugin-upload/admin/src/utils/tests/getType.test.js
@@ -1,6 +1,13 @@
import getType from '../getType';
describe('UPLOAD | utils | getType', () => {
+ it('should return file if mime does not exits', () => {
+ const mime = undefined;
+ const expected = 'file';
+
+ expect(getType(mime)).toEqual(expected);
+ });
+
it('should return image if mime string contains image', () => {
const mime = 'image/png';
const expected = 'image';