.NET Image Server Upload

How it works

  1. You specify the upload options when the rich text editor is initialized on client side.
  2. When an image is inserted, the javascript editor automatically makes an AJAX request to the server.
  3. Once the request hits the server, it stores the image and sends back to the client the link to the uploaded image.

Important: By default the rich text editor uploads images to our servers i.froala.com, however they are being stored there only temporary and might be deleted at anytime. We recommend to upload images to your own server and store them there instead.

Jump to Complete Example

Initialize the javascript editor

To get started, the rich text editor needs to have the imageUploadURL option set as the URL where you want to have the images uploaded. Additionally, you can set other options related to the way the images are being uploaded and what data your server receives: imageUploadParam, imageUploadParams, imageUploadMethod, imageMaxSize, imageAllowedTypes.

<script>
  $(function() {
    $('.selector').froalaEditor({
      // Set the image upload URL.
      imageUploadURL: '/FroalaApi/UploadImage'
    })
  });
</script>

Receive the uploaded image and store it

The server implementation is responsible for receiving the request and handling it appropriately. In .NET, the uploaded image is available in the HttpContext global variable. The .NET editor SDK is designed to automatically detect the uploaded image, so you just have to specify the path where to store it.

Note: The path of the image is relative to the root of the project.

string uploadPath = "/Public/";
object response = FroalaEditor.Image.Upload(System.Web.HttpContext.Current, uploadPath);

For the uploaded image to be stored correctly, the server should have the rights to write in the uploads folder. Additionally, you should check that the uploaded image is public accessible in browser so it can be displayed to your users.

Return the path to the uploaded image

If the save action is completed successfully, the SDK is generating an ImageResponse object with the absolute path to the uploaded image, so your server just have to return it back to the client side.

return Json(response);

Complete Example

<script>
  $(function() {
    $('.selector').froalaEditor({
      // Set the image upload URL.
      imageUploadURL: '/FroalaApi/UploadImage'
    })
  });
</script>
using System;
using System.Web.Mvc;

namespace demo.Controllers
{
    public class FroalaApiController : Controller
    {
        public ActionResult UploadImage()
        {
            string uploadPath = "/Public/";

            try
            {
                return Json(FroalaEditor.Image.Upload(System.Web.HttpContext.Current, uploadPath));
            }
            catch (Exception e)
            {
                return Json(e);
            }
        }
    }
}