kolkov / angular-editor

A simple native WYSIWYG editor component for Angular 6 -14+
https://angular-editor.kolkov.ru
MIT License
674 stars 361 forks source link

Working .netcore sample for uploading an image #408

Open michaelonz opened 3 years ago

michaelonz commented 3 years ago

I have looked through these issues and cant seem to find a complete working example of uploading an image file to a server - can anyone point me in the right direction with some sample code?

Using .net core 5 rest api backend and angular 9 front end.

I have the editor working in reactive forms but cant work out how to make the imageupload work with .net core

rasmusbuchholdt commented 3 years ago

I managed to get the image with the following code:

[HttpPost("image")]
public async Task<UploadPageImageResponse> InsertImage([FromForm] IFormFile file)
{
    var resp = new UploadPageImageResponse()
    {
        Status = true,
        OriginalName = "Test",
        GeneratedName = "Test 2",
        Extension = ".png",
        Msg = "My message",
        ImageUrl = "https://raw.githubusercontent.com/kolkov/angular-editor/master/docs/angular-editor-logo.png"
    };

    return resp;
}

The response image I return does not get inserted though, let me know if you figure that part out.

rasmusbuchholdt commented 3 years ago

I fixed it with this commit: https://github.com/RasmusBuchholdt/angular-editor/commit/8a9dd01c13a94830e5ee4ac2ed5ba858f75496dc