How do I pass the <div> element (to get its id) from CKEditor-->uploads()-->_initRequest()?

Volk Volk 551 Reputation points
2024-01-20T17:33:28.04+00:00

Hi! I have 2 CKEditor fields (<div></div>) in the View.

<div id="editor_1">
     @Html.Raw(@Model.Description_1)
</div>

<div id="editor_2">
     @Html.Raw(@Model.Description_2)
</div>

There is a code that transmits the uploaded image to the controller:

<script>

class MyUploadAdapter {
	
	upload() {
		return this.loader.file
			.then( file => new Promise( ( resolve, reject ) => {
				this._initRequest();
				this._initListeners( resolve, reject, file );
				this._sendRequest( file );
			} ) );
	}

	_initRequest() {
		const xhr = this.xhr = new XMLHttpRequest();
	}
}

</script>

How do I pass in _initRequest() a link to the elements <div id="editor_1"> and <div id="editor_2"> to understand which field the user is uploading the image to (I need to get the field id)? I tried to figure it out in the controller (in Request class) where I receive the uploaded image, but I couldn't.

foreach (IFormFile photo in Request.Form.Files)

Thanks!

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,772 questions
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
1,039 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 71,101 Reputation points
    2024-01-23T17:13:14.98+00:00

    its not clear why you need the div id, the loader just returns the server url of the uploaded file. as this is a 3rd party library you should ask your question on their support:

    https://ckeditor.com/docs/ckeditor5/latest/support/index.html


  2. Volk Volk 551 Reputation points
    2024-01-25T14:12:50.26+00:00

    I solved the problem by myself by getting the focus - in which field the image is uploaded. The issue is closed. https://ckeditor.com/docs/ckeditor5/latest/framework/deep-dive/ui/focus-tracking.html

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.