我的代码将文件发送到node.js服务器,并且正在100%工作,但是我想传递一些数据,例如用户ID或UserName。我该怎么办?
HTML组件:
<form>
<input type="file" name="photo" ng2FileSelect [uploader]="uploader">
<button type="button" (click)="uploader.uploadAll()">Upload an Image</button>
</form>
Ts组件:
import { Component, OnInit } from '@angular/core';
import { FileUploader} from 'ng2-file-upload/ng2-file-upload';
@Component({
selector: 'app-photos',
templateUrl: './photos.component.html',
styleUrls: ['./photos.component.css']
})
export class PhotosComponent implements OnInit {
public uploader: FileUploader = new FileUploader({ url: URL, itemAlias: 'photo'});
ngOnInit() {
this.uploader.onAfterAddingFile = (file) => { file.withCredentials = false; };
this.uploader.onCompleteItem = (item: any, response: any, status: any, headers: any) => {
alert('File uploaded successfully');
}
}
// this function to Get Information of user
getUser() {
this.userservice.GetUserById(this.user._id).subscribe(
data => {
this.user = data.result;
},
err => console.log(err)
);
}
}