Angular-5 froala 图片上传

Angular-5 froala Image Upload

我的 angular 项目使用 froala 编辑器。我将上传路径指向我的资产文件,但是当我浏览页面时它说 "something went wrong" 我检查了开发者工具错误,它显示图像路径为 404。

我的 ts 文件是这样的

import { Component, OnInit } from '@angular/core';


@Component({
    selector: 'app-editor',
    templateUrl: './editor.component.html',
    styleUrls: ['./editor.component.css']
})
export class EditorComponent implements OnInit {

    constructor() { }

    public editorContent: string ="";

    ngOnInit() {
    }

    public onClickMe()
    {
        alert(this.editorContent);
    }

    public options: Object = {
        charCounterCount: true,
        // Set the image upload parameter.
        imageUploadParam: 'image_param',

        // Set the image upload URL.
        imageUploadURL: 'assets/upload_image',

        // Additional upload params.
        imageUploadParams: {id: 'my_editor'},

        // Set request type.
        imageUploadMethod: 'POST',

        // Set max image size to 5MB.
        imageMaxSize: 5 * 1024 * 1024,

        // Allow to upload PNG and JPG.
        imageAllowedTypes: ['jpeg', 'jpg', 'png'],

    };
}

怎么了?

我的 html 文件是这样的

<div [froalaEditor]="options" [(froalaModel)]="editorContent"></div>

<button type="button" class="btn btn-success" (click)="onClickMe()">Kaydet</button>

尝试用这个替换你的对象。

public options: Object = {
    charCounterCount: true,
    // Set the image upload parameter.
    imageUploadParam: 'image_param',

    // Set the image upload URL.
    imageUploadURL: 'assets/upload_image',

    // Additional upload params.
    imageUploadParams: {id: 'my_editor'},

    // Set request type.
    imageUploadMethod: 'POST',

    // Set max image size to 5MB.
    imageMaxSize: 5 * 1024 * 1024,

    // Allow to upload PNG and JPG.
    imageAllowedTypes: ['jpeg', 'jpg', 'png'],
    events:  {
  'froalaEditor.initialized':  function () {
    console.log('initialized');
  },
  'froalaEditor.image.beforeUpload':  function  (e,  editor,  images) {
    //Your code 
    if  (images.length) {
      // Create a File Reader.
      const  reader  =  new  FileReader();
      // Set the reader to insert images when they are loaded.
      reader.onload  =  (ev)  =>  {
        const  result  =  ev.target['result'];
        editor.image.insert(result,  null,  null,  editor.image.get());
        console.log(ev,  editor.image,  ev.target['result'])
      };
      // Read image as base64.
      reader.readAsDataURL(images[0]);
    }
    // Stop default upload chain.
    return  false;
  }

};}