1
私はdjango REST APIをmodels.ImageField()で持っています。私はdjangoから写真をアップロードすることができます。角度4からDjango RESTへの画像アップロード
.htmlを
<div class="form-group">
<label for="usr">Upload your new photo(Optional):</label> <input type="file" accept=".jpg,.png,.jpeg" (change)="attachFile($event)">
<br>
<img src="{{imageSrc}}" height="250" weight="250" alt="Image preview..." />
</div>
component.ts
Update(form){
let body = {
house: 3,
photourl: this.imageSrc
}
console.log(this.imageSrc)
this.http.Post('http://127.0.0.1:8000/api/photos', body).subscribe(res => console.log(res))
console.log(form)
}
attachFile(event) : void {
var reader = new FileReader();
let _self = this;
reader.onload = function(e) {
_self.imageSrc = reader.result;
};
reader.readAsDataURL(event.target.files[0]);
}
エラーは、私はこの乗り越えるべきか、this.imageSrcはファイルではありませんでしょうか?どのデータをImageField()に送る必要がありますか