While working on my project, I encountered an issue with uploading video files using ng2-file-upload to the server. The photo upload functionality is working fine, but when attempting to upload a video file larger than 27MB, the process gets canceled automatically once Uploader.UploadAll method is called. An error message "Failed to load resource: net::ERR_CONNECTION_RESET" appears in the browser console.
I need to be able to upload video files of at least 100MB in size.
Below is the HTML code snippet:
<div *ngIf="authService.currentUser && authService.currentUser.id == user.id" class="row mt-3">
<div class="col-md-3">
<h3>Upload files</h3>
<div ng2FileDrop
[ngClass]="{'nv-file-over': hasBaseDropZoneOver}"
(fileOver)="fileOverBase($event)"
[uploader]="uploader"
class="card bg-faded p-3 text-center mb-3 my-drop-zone">
<i class="fa fa-upload fa-3x"></i>
Drop Videos Here
</div>
Single
<input type="file" ng2FileSelect [uploader]="uploader" />
</div>
<div class="col-md-9" style="margin-bottom: 40px" *ngIf="uploader?.queue?.length">
<h3>Upload queue</h3>
<p>Queue length: {{ uploader?.queue?.length }}</p>
<table class="table">
<thead>
<tr>
<th width="50%">Name</th>
<th>Size</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of uploader.queue">
<td><strong>{{ item?.file?.name }}</strong></td>
<td *ngIf="uploader.options.isHTML5" nowrap>{{ item?.file?.size/1024/1024 | number:'.2' }} MB</td>
</tr>
</tbody>
</table>
<div>
<div>
Queue progress:
<div class="progress mb-4">
<div class="progress-bar" role="progressbar" [ngStyle]="{ 'width': uploader.progress + '%' }"></div>
</div>
</div>
<button type="button" class="btn btn-success btn-s"
(click)="uploader.uploadAll()" [disabled]="!uploader.getNotUploadedItems().length">
<span class="fa fa-upload"></span> Upload
</button>
<button type="button" class="btn btn-warning btn-s"
(click)="uploader.cancelAll()" [disabled]="!uploader.isUploading">
<span class="fa fa-ban"></span> Cancel
</button>
<button type="button" class="btn btn-danger btn-s"
(click)="uploader.clearQueue()" [disabled]="!uploader.queue.length">
<span class="fa fa-trash"></span> Remove
</button>
</div>
</div>
</div>
The TypeScript code for handling file uploads:
initializeUploader() {
this.uploader = new FileUploader({
url: this.baseUrl + 'api/users/' + this.authService.decodedToken.nameid + '/videos',
authToken: 'Bearer ' + localStorage.getItem('token'),
isHTML5: true,
allowedFileType: ['video'],
removeAfterUpload: true,
autoUpload: false,
maxFileSize: 100 * 1024 * 1024
});
this.uploader.onAfterAddingFile = (file) => { file.withCredentials = false; };
this.uploader.onSuccessItem = (item, response, status, headers) => {
if (response) {
const res: Video = JSON.parse(response);
const video = {
id: res.id,
url: res.id,
dateAdded: res.dateAdded,
description: res.description,
fileExtension: res.fileExtension,
thumbs: ''
};
this.videos.push(video);
}
};
}
If you have any insights or solutions to resolve this problem, especially with regards to uploading files larger than 27MB, I would greatly appreciate it. Thank you.
Best regards,