Days
Hours
Minutes
Seconds
x

Froala Editor v4.3 is hereLEARN MORE

Skip to content

.NET Image Server Upload

How it works

  1. Specify upload options when initializing the editor.
  2. On image insertion, the editor automatically makes an AJAX request to the server.
  3. Once the request reaches the server, it stores the image and sends back to the client the link to the uploaded image.

Jump to Complete Example

Initialize the editor

First, add the imageUploadURL option, as its value enter the upload destination for the images.

Next, set any additional options to configure upload methods and allowed file types: imageUploadParam, imageUploadParams, imageUploadMethod, imageMaxSize, imageAllowedTypes.

<script>
  new FroalaEditor('.selector', {
    // 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 detects the uploaded image automatically but you 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);

To store the uploaded image, the server needs write rights on the uploads folder. Additionally, check uploaded images are publicly accessible in the browser.

Return the uploaded image path

If the save action is successful, the SDK generates an ImageResponse object with the absolute path to the uploaded image and the server returns the path to the client side.

return Json(response);

Complete Example

<script>
  new FroalaEditor('.selector', {
    // 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);
            }
        }
    }
}

Do you think we can improve this article? Let us know.