私はあなたがアップロードするファイルを選択すると、それはすでにローカルから選択されているのでフォルダ。右? NodeJSをNodeJSサーバーに送信して保存するようにNodeJSについて言及しました。私はこれが開始する何かであなたを役に立てば幸い
updateImage(fileToUpload) {
const body = JSON.stringify(fileToUpload);
const headers = new Headers({ 'Content-Type': 'image/jpeg' });
return this.http.patch(this.config.host + '/photo/', body, { headers: headers })
.map((response: Response) => {
console.log(response.json().data);
})
.catch((error: Response) => {
console.log("Error: ", error);
return Observable.throw(error.json());
});
}
:
import { Component, OnInit, OnDestroy, ChangeDetectorRef } from '@angular/core';
...
fileToUpload: File;
constructor(private imageService: ImageService,
private changeDetectorRef: ChangeDetectorRef) { }
fileChange(input) {
this.readFiles(input.files);
}
readFile(file, reader, callback){
reader.onload =() => {
callback(reader.result);
this.fileToUpload = reader.result;
this.onImageUpload();
}
reader.readAsDataURL(file);
}
readFiles(files, index=0){
let reader = new FileReader();
if (index in files) {
this.readFile(files[index], reader, (result) => {
var img = document.createElement("img");
img.src = result;
this.readFiles(files, index+1);
});
} else {
this.changeDetectorRef.detectChanges();
}
}
onImageUpload() {
this.imageService.updateImage(this.fileToUpload).subscribe(
(photo: Photo) => {
if (photo) { ... }
}
);
}
次にサービスで、あなたはこのような何かを(私はJPGを検討している)を実行したいです。
これをご覧ください:http://stackoverflow.com/questions/41547945/write-to-a-local-file-using-angular2-typescript-locally – DeborahK
私はそれを済ませました。バックエンドにdjangoを使用する。 – maadi