Does anyone know if it's possible to change the units display for uploaded files? I uploaded a file that is 600 MB, and the display says 0.6 Gib... It's not real user friendly. I've checked the instructions on the website, and cannot find anything beyond how to change the filesizeBase
from 1000 to 1024.
Asked
Active
Viewed 2,620 times
1

Kenny
- 2,150
- 2
- 22
- 30
3 Answers
1
I had a similar need because I had to show the units always on KB. I found a function in dropzone.js called filesize and I just overwritten it by the next one on my own code:
Dropzone.prototype.filesize = function(size) {
var selectedSize = Math.round(size / 1024);
return "<strong>" + selectedSize + "</strong> KB";
};
I think you have to overwrite the same function but adapt it for your needs.
I hope is still useful for you.

Gonzalo Muro
- 196
- 1
- 7
-
Thanks for the suggestion! – Kenny Jul 07 '15 at 15:04
0
This is more similar to the existing filesize function included in Dropzone (except more verbose).
Dropzone.prototype.filesize = function (bytes) {
let selectedSize = 0;
let selectedUnit = 'b';
let units = ['kb', 'mb', 'gb', 'tb'];
if (Math.abs(bytes) < this.options.filesizeBase) {
selectedSize = bytes;
} else {
var u = -1;
do {
bytes /= this.options.filesizeBase;
++u;
} while (Math.abs(bytes) >= this.options.filesizeBase && u < units.length - 1);
selectedSize = bytes.toFixed(1);
selectedUnit = units[u];
}
return `<strong>${selectedSize}</strong> ${this.options.dictFileSizeUnits[selectedUnit]}`;
}
Example:
339700 bytes -> 339.7 KB (instead of 0.3 MB which is what Dropzone returns by default)

caseyjhol
- 3,090
- 2
- 19
- 23
0
This piece of code works for me:
Dropzone.prototype.filesize = function (bytes) {
let selectedSize = 0;
let units = ['B', 'KB', 'MB', 'GB', 'TB'];
var size = bytes;
while (size > 1000) {
selectedSize = selectedSize + 1;
size = size/1000;
}
return "<strong>" + Math.trunc(size * 100)/100 + "</strong> " + units[selectedSize];
}
I'm dividing by 1000, because otherwise I get 1010 KB, instead of 1.01 MB.

Trevy Burgess
- 499
- 5
- 12