Asp.net ядро MVC.С помощью редактора отправьте запрос на сервер, чтобы получить список файлов, уже загруженных на сервер.Но менеджер редактирования Froala возвращает критическую ошибку.
Настройки редактора Froala:
// Set the load images request URL
imageManagerLoadURL: "/GetUploadedList",
// Set the load images request type
imageManagerLoadMethod: "POST",
// Set page size
imageManagerPageSize: 20,
// Set a scroll offset (value in pixels)
imageManagerScrollOffset: 10
})
.on('froalaEditor.imageManager.error', function (e, editor, error, response) {
// Custom error message returned from the server.
if (error.code === 0) { alert("error"); }
// Bad link.
else if (error.code === 1) { alert("bad link"); }
// No link in upload response.
else if (error.code === 2) { alert("no link"); }
// Error during image upload.
else if (error.code === 3) { alert("during image"); }
// Parsing response failed.
else if (error.code === 4) { alert("parsing error"); }
// Image too large.
else if (error.code === 5) { alert("large image"); }
// Invalid image type.
else if (error.code === 6) { alert("invalid image"); }
// Image can be uploaded only to same domain in IE 8 and IE 9.
else if (error.code === 7) { alert("ie8 error"); }
})
Метод asp:
[HttpPost("GetUploadedList")]
[Produces("application/json")]
public IActionResult UploadedList()
{
string[] listFiles = Directory.GetFiles(Path.Combine(_hostingEnvironment.WebRootPath, "uploadedImages/admin"));
List<object> jsonListFiles = new List<object>();
//List<object> jsonListFiles = new List<object>()
//{
// new { src = "https://www.froala.com/assets/editor/media_files/photo1.jpg" },
// new { src = "https://www.froala.com/assets/editor/media_files/photo2.jpg" },
// new { src = "https://www.froala.com/assets/editor/media_files/photo3.jpg" }
//};
//List<object> jsonListFiles = new List<object>()
//{
// new { url = "https://www.froala.com/assets/editor/media_files/photo1.jpg", thumb = "https://www.froala.com/assets/editor/media_files/photo1.jpg", tag = "pencils", name = "Photo 1 Name", id = "10545464" },
// new { url = "https://www.froala.com/assets/editor/media_files/photo2.jpg", thumb = "https://www.froala.com/assets/editor/media_files/photo2.jpg", tag = "musician", name = "Photo 2 Name", id = "4532453453" },
// new { url = "https://www.froala.com/assets/editor/media_files/photo3.jpg", thumb = "https://www.froala.com/assets/editor/media_files/photo3.jpg", tag = "umbrella", name = "Photo 3 Name", id = "4345348889" }
//};
foreach (var item in listFiles)
{
jsonListFiles.Add(new
{
name = item.Substring(item.LastIndexOf("\\") + 1),
url = item,
thumb = item,
tag = "uploadedImages/admin"
});
}
var jsonObj = JsonConvert.SerializeObject(jsonListFiles);
return Json(jsonObj);
}
На самом сайте редактор выдает форматвозвращенные данные, такие как:
[
{
"url": "http://exmaple.com/images/photo1.jpg",
"thumb": "http://exmaple.com/thumbs/photo1.jpg",
"tag": "flower"
},
{
"url": "http://exmaple.com/images/photo2.jpg",
"thumb": "http://exmaple.com/thumbs/photo2.jpg",
"tag": "sport"
}
]
Однако, это вызывает ошибку сценария.