我正在尝试创建一种简单的上载方法,该方法将选定的图像移动到项目中的img文件夹中,而且还将文件的名称和扩展名存储在字符串中,以供以后使用。 / p>
我一直想出一个函数来将文件移动到文件夹,并返回移动文件的名称和扩展名。
HTML
<label class="image-upload-container btn button-wbm">
<div style="color: #a2a2a2">Image</div>
<input #imageInput
type="file"
title="Upload Image"
accept="image/*">
</label>
TS
export class AddPostComponent implements OnInit {
@Output() public newPost = new EventEmitter<Post>();
constructor() { }
ngOnInit() {
}
addPost(title: HTMLInputElement, body: HTMLInputElement, count: HTMLInputElement, image: File): boolean {
const post = new Post("Test author",title.value, body.value, new Date(), count.valueAsNumber, 0, [], processImage(image));
this.newPost.emit(post);
return false;
}
processFile(file:File):string{
//move file to project/images/ <<-- point where I'm stuck at
var name = file.name+file.type;
return name;
}
}