Skip to content

Commit 3715701

Browse files
authored
Fix/ji 6488 handle av file upload request error (#277)
* JI-6488 handle file upload request error * JI-6488 check file size before upload * JI-6488 hardcode max file size in bytes
1 parent b3af10f commit 3715701

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

scripts/h5peditor-file-uploader.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,31 @@ H5PEditor.FileUploader = (function ($, EventDispatcher) {
2020
* @param {string} filename Required due to validation
2121
*/
2222
self.upload = function (file, filename, context = {}) {
23+
if (file.size > 2147483648) { // file bigger than 2 GB
24+
var uploadComplete = {
25+
...context,
26+
error: H5PEditor.t('core', 'fileToLarge'),
27+
data: null
28+
};
29+
self.trigger('uploadComplete', uploadComplete);
30+
return;
31+
}
32+
2333
var formData = new FormData();
2434
formData.append('file', file, filename);
2535
formData.append('field', JSON.stringify(field));
2636
formData.append('contentId', H5PEditor.contentId || 0);
2737

2838
// Submit the form
2939
var request = new XMLHttpRequest();
40+
request.onerror = function () {
41+
var uploadComplete = {
42+
...context,
43+
error: H5PEditor.t('core', 'unknownFileUploadError'),
44+
data: null
45+
};
46+
self.trigger('uploadComplete', uploadComplete);
47+
}
3048
request.upload.onprogress = function (e) {
3149
if (e.lengthComputable) {
3250
self.trigger('uploadProgress', {

0 commit comments

Comments
 (0)