[Fixed v5.2.0] Check maximum filesize before uploading.

BrianNLD

New Member
YetiShare User
Jan 2, 2021
4
2
3
Hello,

For my users I configured a maximum filesize of 1GB. After that I tried to upload a 2GB zip file which started uploading fine. After uploading reached 100% I got an error that the file exceeded the maximum filesize. It looks like Yetishare doesn't check the filesize before uploading.

I tested the same thing with the remote URL upload, and here it works fine. Yetishare checks the filesize before it starts downloading the file. So it seems like the check is missing if you upload from your computer.

It it possible to also add this check when you upload from your own computer? It's a bit more user-friendly and saves bandwidth. Or is it not possible because the files are uploaded in chunks?

brave_wcDhZxmGU0.png
 

adam

Administrator
Staff member
Dec 5, 2009
2,046
108
63
It should indeed alert before uploading. It looks like the latest uploader code ignores the property. You can use the code below to add it back in. Via:

\themes\spirit\views\account\partial\_uploader_javascript.html.twig

Find:

JavaScript:
.on('fileuploadadd', function (e, data) {
After replace:

JavaScript:
{% if acceptedFileTypes|length > 0 %}
    var acceptFileTypes = /^({{ acceptedFileTypesUploaderStr }})$/i;
    for(i in data.originalFiles)
    {
        fileExtension = data.originalFiles[i]['name'].substr(data.originalFiles[i]['name'].lastIndexOf('.')+1);
        if(!acceptFileTypes.test(fileExtension)) {
            alert("{{ t('file_upload_file_type_not_allowed', 'File type not allowed')|escape("js") }} (\""+data.originalFiles[i]['name']+"\")");
            return false;
        }
    }
{% endif %}
With:

JavaScript:
var uploadErrors = [];
        
{% if acceptedFileTypes|length > 0 %}
    var acceptFileTypes = /^({{ acceptedFileTypesUploaderStr }})$/i;
{% endif %}

for(i in data.originalFiles)
{
    if(data.originalFiles[i]['size'] > uploaderMaxSize) {
        uploadErrors.push("{{ t('file_upload_file_is_too_big', 'File is too big')|escape("js") }} (\""+data.originalFiles[i]['name']+"\")");
    }

    {% if acceptedFileTypes|length > 0 %}
        fileExtension = data.originalFiles[i]['name'].substr(data.originalFiles[i]['name'].lastIndexOf('.')+1);
        if(!acceptFileTypes.test(fileExtension)) {
            uploadErrors.push("{{ t('file_upload_file_type_not_allowed', 'File type not allowed')|escape("js") }} (\""+data.originalFiles[i]['name']+"\")");
        }
    {% endif %}
}

if(uploadErrors.length > 0) {
    alert(uploadErrors.join("\n"));
    return false;
}
I'll make a note to review this for the next release.
 
  • Like
Reactions: BrianNLD

BrianNLD

New Member
YetiShare User
Jan 2, 2021
4
2
3
It should indeed alert before uploading. It looks like the latest uploader code ignores the property. You can use the code below to add it back in. Via:

\themes\spirit\views\account\partial\_uploader_javascript.html.twig

Find:

JavaScript:
.on('fileuploadadd', function (e, data) {
After replace:

JavaScript:
{% if acceptedFileTypes|length > 0 %}
    var acceptFileTypes = /^({{ acceptedFileTypesUploaderStr }})$/i;
    for(i in data.originalFiles)
    {
        fileExtension = data.originalFiles[i]['name'].substr(data.originalFiles[i]['name'].lastIndexOf('.')+1);
        if(!acceptFileTypes.test(fileExtension)) {
            alert("{{ t('file_upload_file_type_not_allowed', 'File type not allowed')|escape("js") }} (\""+data.originalFiles[i]['name']+"\")");
            return false;
        }
    }
{% endif %}
With:

JavaScript:
var uploadErrors = [];
       
{% if acceptedFileTypes|length > 0 %}
    var acceptFileTypes = /^({{ acceptedFileTypesUploaderStr }})$/i;
{% endif %}

for(i in data.originalFiles)
{
    if(data.originalFiles[i]['size'] > uploaderMaxSize) {
        uploadErrors.push("{{ t('file_upload_file_is_too_big', 'File is too big')|escape("js") }} (\""+data.originalFiles[i]['name']+"\")");
    }

    {% if acceptedFileTypes|length > 0 %}
        fileExtension = data.originalFiles[i]['name'].substr(data.originalFiles[i]['name'].lastIndexOf('.')+1);
        if(!acceptFileTypes.test(fileExtension)) {
            uploadErrors.push("{{ t('file_upload_file_type_not_allowed', 'File type not allowed')|escape("js") }} (\""+data.originalFiles[i]['name']+"\")");
        }
    {% endif %}
}

if(uploadErrors.length > 0) {
    alert(uploadErrors.join("\n"));
    return false;
}
I'll make a note to review this for the next release.
Thanks, this works!