본문 바로가기
C#

네이버 스마트에디터] 이미지파일 업로드시 Base64인코딩 태그로 수정

by Fastlane 2021. 9. 6.
728x90
반응형

1.  Controllers/WebEditorController.cs – 파일첨부

2.  Views/Shared/WebEditor.ascx – 아래 함수 추가

//base64 이미지삽입 - 업로드 완료페이지에서 호출됨.

    function insertIMGBase64(fileAsString) {

        var sHTML = "<img src='data:image/png;base64," + fileAsString + "'>";

        oEditors.getById["ir1"].exec("PASTE_HTML", [sHTML]);

    }

 


        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ImgUpload(string ckhBorder, HttpPostedFileBase update_image)
        {

            string filePath = Request.Form["filePath"].ToString();

            byte[] fileInBytes = new byte[update_image.ContentLength];
            using (BinaryReader theReader = new BinaryReader(update_image.InputStream))
            {
                fileInBytes = theReader.ReadBytes(update_image.ContentLength);
            }
            string fileAsString = Convert.ToBase64String(fileInBytes);

            StringBuilder strScript = new StringBuilder();

            strScript.AppendLine("  parent.parent.insertIMGBase64('" + fileAsString + "');");
            strScript.AppendLine("  parent.parent.oEditors.getById[\"ir1\"].exec(\"SE_TOGGLE_FILEUPLOAD_LAYER\");");
            strScript.AppendLine("  window.location=\"/WebEditor/ImgUpload\";");

            ViewData["filePath"] = filePath;
            ViewData["strScript"] = strScript.ToString();

            return View();
        }
728x90
반응형

댓글