在我的项目中,我使用了ng2-file-upload上传照片和视频到server.Photo,上传部分工作正常。但是超过27MB的视频文件不能上传我调用Uploader.UploadAll方法然后upload.When方法隐藏和文件上传自动canceled.In浏览器控制台显示一个名为的错误
Failed to load resource: net::ERR_CONNECTION_RESET 我要上传的视频文件至少100MB。
这是html代码
<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>这是我的打字代码
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);
}
};
}请告诉我如何解决这个问题,如果我选择的文件大小超过27MB,就会出现这个问题。
谢谢
发布于 2019-02-02 19:53:59
我解决了这个问题,通过修改文件上传不是ng2- file.This - library.In的问题我的项目在kestrel服务器上运行,所以我在program.cs文件中添加了这一行。
.UseKestrel(options =>
{
options.Limits.MaxRequestBodySize = 209715200;
})这里是拉取代码的地方
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureLogging(builder =>
{
builder.SetMinimumLevel(LogLevel.Warning);
builder.AddFilter("ApiServer", LogLevel.Debug);
builder.AddSerilog();
})
.UseContentRoot(Directory.GetCurrentDirectory())
.UseKestrel(options =>
{
options.Limits.MaxRequestBodySize = 209715200;
})
.UseStartup<Startup>();然后,在控制器类中的RequestFormLimits ()方法之上添加了RequestSizeLimit和upload属性之后
[RequestFormLimits(MultipartBodyLengthLimit = 209715200)]
[RequestSizeLimit(209715200)]
public async Task<IActionResult> Upload(Guid userId,
[FromForm]VideoForCreationDto videoForCreationDto)
{}如果你使用的是iis服务器,那么把这段代码添加到web.config file.Actually我是从另一个place.So上得到的这段代码我不太确定,我认为这对某些人很有帮助,这就是添加这段代码的原因。
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="209715200" />
</requestFiltering>
</security>
</system.webServer>https://stackoverflow.com/questions/54467956
复制相似问题