我正在尝试ng2-file-upload,问题是我不能设置自定义头。到目前为止我已经做到了
在upload-documents.component中
import { Component } from '@angular/core';
import { FileUploader, Headers } from 'ng2-file-upload';
@Component({
moduleId: module.id,
selector: 'sg-uploadcompnent',
templateUrl: '../views/upload-documents.template.html'
})
export class UploadDocumentsComponent {
public uploader: FileUploader = new FileUploader({
url: "http://localhost:port/app/api/upload/",
authToken: "Authorization",
authTokenHeader: "Bearer mytoken871lkdk39829",
isHTML5: true,
**headers: [
{name: "myCustomHeader", value:"some value"}]**
});
}
<style>
.my-drop-zone { border: dotted 3px lightgray; }
.nv-file-over { border: dotted 3px red; } /* Default class applied to drop zones on over */
.another-file-over-class { border: dotted 3px green; }
html, body { height: 100%; }
</style>
<div class="container">
<div class="navbar navbar-default">
<div class="navbar-header">
<a class="navbar-brand" href>The screen to upload files</a>
</div>
</div>
<div class="row">
<div class="col-md-3">
<h3>Select files</h3>
<div ng2FileDrop
[ngClass]="{'nv-file-over': hasBaseDropZoneOver}"
(fileOver)="fileOverBase($event)"
[uploader]="uploader"
class="well my-drop-zone">
Base drop zone
</div>
<div ng2FileDrop
[ngClass]="{'another-file-over-class': hasAnotherDropZoneOver}"
(fileOver)="fileOverAnother($event)"
[uploader]="uploader"
class="well my-drop-zone">
Another drop zone
</div>
Multiple Selection
<input type="file" ng2FileSelect [uploader]="uploader" multiple /><br/>
Single
<input type="file" ng2FileSelect [uploader]="uploader" />
</div>
<div class="col-md-9" style="margin-bottom: 40px">
<h3>Files to upload</h3>
<p>Total: {{ uploader?.queue?.length }}</p>
<table class="table">
<thead>
<tr>
<th width="50%">Name</th>
<th>Size</th>
<th>Progress</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of uploader.queue">
<td><strong>{{ item?.file?.name }}</strong></td>
<td *ngIf="uploader.isHTML5" nowrap>{{ item?.file?.size/1024/1024 | number:'.2' }} MB</td>
<td *ngIf="uploader.isHTML5">
<div class="progress" style="margin-bottom: 0;">
<div class="progress-bar" role="progressbar" [ngStyle]="{ 'width': item.progress + '%' }"></div>
</div>
</td>
<td class="text-center">
<span *ngIf="item.isSuccess"><i class="glyphicon glyphicon-ok"></i></span>
<span *ngIf="item.isCancel"><i class="glyphicon glyphicon-ban-circle"></i></span>
<span *ngIf="item.isError"><i class="glyphicon glyphicon-remove"></i></span>
</td>
<td nowrap>
<button type="button" class="btn btn-success btn-xs"
(click)="item.upload()" [disabled]="item.isReady || item.isUploading || item.isSuccess">
<span class="glyphicon glyphicon-upload"></span> Upload
</button>
<button type="button" class="btn btn-warning btn-xs"
(click)="item.cancel()" [disabled]="!item.isUploading">
<span class="glyphicon glyphicon-ban-circle"></span> Cancel
</button>
<button type="button" class="btn btn-danger btn-xs"
(click)="item.remove()">
<span class="glyphicon glyphicon-trash"></span> Remove
</button>
</td>
</tr>
</tbody>
</table>
<div>
<div>
Queue progress:
<div class="progress" style="">
<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="glyphicon glyphicon-upload"></span> Upload all
</button>
<button type="button" class="btn btn-warning btn-s"
(click)="uploader.cancelAll()" [disabled]="!uploader.isUploading">
<span class="glyphicon glyphicon-ban-circle"></span> Cancel all
</button>
<button type="button" class="btn btn-danger btn-s"
(click)="uploader.clearQueue()" [disabled]="!uploader.queue.length">
<span class="glyphicon glyphicon-trash"></span> Remove all
</button>
</div>
</div>
</div>
我做了这个,效果很好..能够在我的MVC控制器中提取foofoo:
uploader: FileUploader = new FileUploader({
url: URL,
headers: [{ name: 'foofoo', value: 'passengerslivesmatter' }]
});
问题内容: 我仍然很难理解如何将中间件添加到sails.js。我听说过使用policy.js,创建自定义策略,添加到local.js等。所以有人可以告诉我如何将jquery- file-upload-middleware 添加到Sails 应用程序中。提前致谢 问题答案: 在Sails的早期版本中,这将非常困难,因为您无法控制包含自定义中间件的顺序。在v0.10中,这 有点 困难。 注意:以下内容
是否有一个时间格式来指定这样的日期序列到轴在D3和v4?
我想在向url发送请求时添加假用户代理。但它并没有添加假useragent,而是使用默认的useragent。
本文向大家介绍angular2 ng2-file-upload上传示例代码,包括了angular2 ng2-file-upload上传示例代码的使用技巧和注意事项,需要的朋友参考一下 Angular2中有两个比较好用的上传文件的第三方库,一个是ng2-file-upload,一个是ng2-uploader。ng2-uploader是一个轻便的上传文件的支持库,功能较弱,而ng2-file-uplo
Thymeleaf有许多有用的实用程序,如或。我试图添加一个自定义的,但不知道如何注册这一点。
问题内容: 我正在使用Twitter Bootstrap添加图标,没有问题。他们有很多选择。 http://twitter.github.com/bootstrap/base- css.html#icons 但是,我找不到菜单项之一的适当图标。关于“汽车”。我想要的是我想添加我的自定义图标。我怎样才能做到这一点? 问题答案: 您可以通过在自己的类(如)中定义图标来创建自己的图标: 当然要记住使用前