setting a bigger chunkSize for resumable to improve upload speed (has to be 2^N!)

This commit is contained in:
Ralf Becker 2018-12-14 15:15:20 +01:00
parent e52f3493f1
commit fc2cd455ca
2 changed files with 32 additions and 0 deletions

View File

@ -94,6 +94,12 @@ var et2_file = (function(){ "use strict"; return et2_inputWidget.extend(
"type": "string",
"default": '',
"description": "Define types of files that the server accepts. Multiple types can be seperated by comma and the default is to accept everything."
},
chunk_size: {
"name": "Chunk size",
"type": "integer",
"default": 1024*1024,
"description": "Max chunk size, gets set from server-side PHP max_upload_size/2 (must be 2^N)"
}
},
@ -153,6 +159,7 @@ var et2_file = (function(){ "use strict"; return et2_inputWidget.extend(
onError: function(event, name, error) { return self.onError(event,name,error);},
beforeSend: function(form) { return self.beforeSend(form);},
chunkSize: this.options.chunk_size || 1024*1024,
target: egw.ajaxUrl("EGroupware\\Api\\Etemplate\\Widget\\File::ajax_upload"),
query: function(file) {return self.beforeSend(file);},

View File

@ -339,4 +339,29 @@ class File extends Etemplate\Widget
if($valid && !$this->attrs['multiple']) $valid = $valid[0];
}
}
/**
* Set default chunk_size attribute to max_upload_size/2
*
* @param string $cname
* @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont'
*/
public function beforeSendToClient($cname, array $expand=null)
{
$form_name = self::form_name($cname, $this->id, $expand);
$upload_max_filesize = ini_get('upload_max_filesize');
$unit = strtolower(substr($upload_max_filesize, -1));
if (!is_numeric($unit)) $upload_max_filesize *= $unit == 'm' ? 1024*1024 : 1024;
if ($upload_max_filesize > 1024*1024)
{
// resumable chunkSize has to be 2^N
$n = 10;
while(1<<(1+$n) < $upload_max_filesize-1024*1024)
{
$n++;
}
self::setElementAttribute($form_name, 'chunk_size', 1 << $n);
}
}
}