Beispiel #1
0
        // - /umbraco/backoffice/EditorJs/ImageTool/UploadByFile
        public JsonResult <UploadResponse> UploadByFile()
        {
            UploadResponse r         = new UploadResponse(0);
            var            ctx       = HttpContext.Current;
            var            request   = ctx.Request;
            var            imagefile = request.Files["image"];

            if (imagefile != null)
            {
                // - save uploaded file to the default upload-temp of Umbraco
                string tempfile = string.Format("/App_Data/TEMP/FileUploads/{0}{1}", System.Guid.NewGuid(), System.IO.Path.GetExtension(imagefile.FileName));
                string filepath = ctx.Server.MapPath(tempfile);

                imagefile.SaveAs(filepath);
                IPublishedContent media = MediaHelper.AddImageByFile(Services.MediaService, Services.ContentTypeBaseServices, Umbraco, imagefile.FileName, filepath);

                r = MediaHelper.PrepareResponse(true, media);
            }

            // ** we need to return the value in this weird way to prevent the JSON auto-protection to kick in **
            //https://our.umbraco.com/forum/extending-umbraco-and-using-the-api/95105-umbracoauthorizedjsoncontroller-adds-garbled-json-to-front-of-all-results
            return(Json(r));
        }