-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Insert Image #555
Comments
Hi Andrew, One question – do you want to insert an image of which you know URL already? Like: editor.execute( 'insertImage', 'https://url/to/the/image' ); Which would result in inserting <img src="https://url/to/the/image"> I'm asking because you mentioned uploading so I also thought that perhaps you would like to upload an image of which you have an URL or of which you have a source (e.g. as a |
Can I insert image using these two methods:
Thanks for your response. |
1) Inserting via URLSurprisingly, we don't have a specific command for this action because none of the existing features needed it already. However, this is pretty simple: import ModelElement from '@ckeditor/ckeditor5-engine/src/model/element';
function insertImage( editor, imageUrl, imageAlt ) {
const doc = editor.document;
doc.enqueueChanges( () => {
const imageElement = new ModelElement( 'image', {
src: imageUrl,
alt: imageAlt
} );
editor.data.insertContent( imageElement, doc.selection );
} );
} Executing In the future, we may create a command which does this. 2) Inserting via fileHere, we already have a command and even an adapter for CKFinder. We also have the "File button" UI component which opens a "browser file" window and lets you choose an image from your disk. Those features are implemented in these plugins:
Note: These plugins are not yet included in the builds so you'll need to customise one or simply integrate the editor directly into your app. |
BTW, enabling the |
We don't have a live demo of this yet, but this is a screencast from one of our manual tests: This is its code: |
That's what I want. I appreciate your quick response and the solution(screen cast). Thank you very much. Andrew |
I'd actually keep this open because I'd like if there was some documentation for that. |
Hello @Reinmar, I am also interested by inserting an image node at the current position (with an inline editor). import ModelElement from '@ckeditor/ckeditor5-engine/src/model/element';
function insertImage( editor, imageUrl, imageAlt ) {
const doc = editor.document;
doc.enqueueChanges( () => {
const imageElement = new ModelElement( 'image', {
src: imageUrl,
alt: imageAlt
} );
editor.data.insertContent( imageElement, doc.selection );
} );
} But I get the error model-position-before-root. I would be very grateful if somebody can help me! |
The code you posted is correct. Or at least it seems so at the first glance. You used the correct method. Actually, I tested this code when writing the Quick start guide and it worked (as proved by screenshots). But I remember that I had a similar error at some point when writing that guide and I had some simple issue in my code... ;| Could you post a stack trace? And how are you loading this feature into the editor? Because if you try to use a CKEditor 5 build then it might not work because of that. |
What I meant is that if you use an already precompiled code (e.g. one of the builds) and then import This is inconvenient and, as I reported in https://github.com/ckeditor/ckeditor5-engine/issues/858#issuecomment-336994447, we'll work on improving this situation. |
InsertImage feature is in development mode? Why bcz I am using https://cdn.ckeditor.com/ckeditor5/1.0.0-alpha.1/inline/ckeditor.js ckeditor5 build plugin, Insert image feature not working in the latest CKEDitor5.Please refer the jsfiddle examples by using inline editor https://jsfiddle.net/vrVAP/3722/ |
I extended my answer for https://stackoverflow.com/questions/46765197/how-to-enable-image-upload-support-in-ckeditor-5 to contain code snippets. Please read it because it clarifies what you need to do to enable image upload in the builds (which can be done by just configuring the editor). And Require.JS has nothing to do with image upload and isn't needed here at all. You just need to configure one of the existing (and included in all builds) upload adapters or write your own adapter. |
I am using require JS plugin to config the JS files in my project. How to config CKEditor5 in the requireJS? |
I'm sorry, but I have no idea what you mean and what problem you have. |
I mean how to call CKEditor5 plugin by using requireJS? And also How to add Underline,code etc.. icons into CKEditor5? |
Hi @Reinmar, Sorry for my late reply and thank you for great explanation and link! Wrong import: import InlineEditor from '@ckeditor/ckeditor5-build-inline'
import ModelElement from '@ckeditor/ckeditor5-engine/src/model/element' Correct import: import InlineEditor from '@ckeditor/ckeditor5-editor-inline/src/inlineeditor'
import ModelElement from '@ckeditor/ckeditor5-engine/src/model/element' |
Hi @Reinmar |
@Reinmar InlineEditor
.create( document.querySelector( '#imageEditor1'),{
toolbar: ['undo','redo'],
ckfinder: {
uploadUrl: '${pageContext.request.contextPath}/uploadImage.html?command=QuickUpload&type=Files&responseType=json
}
})
.catch( error => {
console.error( error );
} ); I am returning a json of the format as shown below. But the upload adapter always alerts with message "Cannot upload file : dubai.jpg" Response in json format from my service:
When I debug, I am getting the instance "this" as undefined and subsequently the reference to the XMLHttpRequest object "xhr" also is undefined. Please help me and tell me If I am doing this the wrong way. Do I have to code a new adapter altogether? Thank You. Regards, |
The source of the CKFinder upload adpater is here: https://github.com/ckeditor/ckeditor5-adapter-ckfinder/blob/master/src/uploadadapter.js. Maybe it will help you tracking the issue because it's hard for me to guess what might've gone wrong. |
Thank you for the quick reply. Can you tell me whether I have used the built in ck finder upload adapter in the proper way? Whether I am returning a proper response? |
It has just one configuration option – the URL to which the file is uploaded. So if you've set that, then yes. |
Hi! This is an issue tracker. Unless you're able to prove that there's an issue, a correct place to ask questions like this would be https://stackoverflow.com/questions/tagged/ckeditor5. However, you're asking to debug your specific integration, so I don't think that anyone will be able to help you there anyway. |
Here is example, how to implement it into Laravel controller with http://laravel-mediable.readthedocs.io/en/latest/uploader.html uploader
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hi, |
@rushi02 CKFinder is commercial software and we cannot share the source code of the server connector with you, sorry. |
I'm using Summernote as my editor. It works well. But recently I have a new project which need to save document as Markdown file.
CKEditor 5 looks promising and can save document as Markdown file.
In Summernote, I can use
onImageUpload()
callback function trigger myloadImage()
function, get the URL and using$('#instruction').summernote('insertImage', imgURL)
insert the image.How can I insert image in CKEditor 5?
Thanks,
Andrew
The text was updated successfully, but these errors were encountered: