如何使用angular2在API中存储base64图像字符串?

如何使用angular2在API中存储base64图像字符串?,angular,Angular,我是新手 我的任务是转换base64字符串中的图像,并将该字符串存储在API json中 我已将图像正确转换为字符串格式,但我不知道如何在后端存储该字符串。拜托,我需要你们的帮助 HTML ---- <div class="col-lg-8"> <input type="file" accept="image/*" (change)="changeListener($event)"> <div *ngIf="image

我是新手

我的任务是转换base64字符串中的图像,并将该字符串存储在API json中

我已将图像正确转换为字符串格式,但我不知道如何在后端存储该字符串。拜托,我需要你们的帮助

    HTML
    ----
    <div class="col-lg-8">
    <input type="file" accept="image/*"
    (change)="changeListener($event)">
    <div *ngIf="imageToShow">
        <img src="{{imageToShow}}" class= "center" alt="">
    </div>
    </div>

    TS
    ---
    imageToShow: string = null;

   ngOnInit() {
   this.category_info = JSON.parse
('{"category":{"image":"","name":"","description":""
,"definition":"","type":"","title":"","icon_name":""}}');
   }
    changeListener($event) : void {
      this.readThis($event.target);
    }

    readThis(inputValue: any): void {
      var file:File = inputValue.files[0];
      var myReader:FileReader = new FileReader();
      myReader.onloadend = (e) => {
        this.imageToShow = myReader.result;
        console.log(this.imageToShow);
      }
      myReader.readAsDataURL(file);
    }  
HTML
----
TS
---
imageToShow:string=null;
恩戈尼尼特(){
this.category_info=JSON.parse
(“{”类别“{”图像“:”名称“:”说明“:”
,“定义”:“类型”:“标题”:“图标名称”:“}”);
}
changeListener($event):无效{
this.readThis($event.target);
}
readThis(inputValue:any):void{
var file:file=inputValue.files[0];
var myReader:FileReader=newfilereader();
myReader.onloadend=(e)=>{
this.imageToShow=myReader.result;
console.log(this.imageToShow);
}
myReader.readAsDataURL(文件);
}  
From the Base64 String, Please remove Content Type string **'data:image/png;base64,'**. You can send the Base64 content string to the Backend API as POST method using Angular HTTPClient Service.

JSON Structure:

    {
        id: 0,
        content-type: :image/png
        base64-content : "image base64 content"
    }