mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-09 16:24:51 +00:00
Merge pull request #4684 from mbliznikova/3596_provide_error_message_for_too_large_files
Provide the error message if a file to upload is too large, issue #3596
This commit is contained in:
commit
381e23e172
1 changed files with 17 additions and 0 deletions
|
@ -1084,6 +1084,16 @@ export default {
|
|||
return App.util.format.timeAgo(ts);
|
||||
},
|
||||
|
||||
formatBytes(bytes, decimals = 2) {
|
||||
if (!+bytes) {
|
||||
return '0 Bytes'
|
||||
}
|
||||
const dec = decimals < 0 ? 0 : decimals
|
||||
const units = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
||||
const quotient = Math.floor(Math.log(bytes) / Math.log(1024))
|
||||
return `${parseFloat((bytes / Math.pow(1024, quotient)).toFixed(dec))} ${units[quotient]}`
|
||||
},
|
||||
|
||||
fetchProfile() {
|
||||
let tags = {
|
||||
public: 'Public',
|
||||
|
@ -1194,6 +1204,13 @@ export default {
|
|||
}, 300);
|
||||
}).catch(function(e) {
|
||||
switch(e.response.status) {
|
||||
case 413:
|
||||
self.uploading = false;
|
||||
io.value = null;
|
||||
swal('File is too large', 'The file you uploaded has the size of ' + self.formatBytes(io.size) + '. Unfortunately, only images up to ' + self.formatBytes(self.config.uploader.max_photo_size * 1024) + ' are supported.\nPlease resize the file and try again.', 'error');
|
||||
self.page = 2;
|
||||
break;
|
||||
|
||||
case 451:
|
||||
self.uploading = false;
|
||||
io.value = null;
|
||||
|
|
Loading…
Reference in a new issue