React Ckeditor Filerepository-no-upload-adapter: Upload Adapter Is Not Defined
Simple upload adapter
The unproblematic upload adapter plugin allows uploading images to your server using the XMLHttpRequest
API with a minimal editor configuration.
See the Server–side configuration section to learn about the requirements your server–side application must see to support this upload adapter.
Bank check out the comprehensive Image upload overview to learn virtually other ways to upload images into CKEditor 5.
# Installation
First, install the @ckeditor/ckeditor5-upload
package:
npm install --salve @ckeditor/ckeditor5-upload
Add the SimpleUploadAdapter
to your plugin list and configure the feature. For instance:
import SimpleUploadAdapter from '@ckeditor/ckeditor5-upload/src/adapters/simpleuploadadapter'; ClassicEditor .create( document.querySelector( '#editor' ), { plugins: [ SimpleUploadAdapter, ... ], toolbar: [ ... ], simpleUpload: { // Feature configuration. } } ) .so( ... ) .grab( ... );
# Configuration
The client side of this feature is configurable using the config.simpleUpload
object.
import SimpleUploadAdapter from '@ckeditor/ckeditor5-upload/src/adapters/simpleuploadadapter'; ClassicEditor .create( certificate.querySelector( '#editor' ), { plugins: [ SimpleUploadAdapter, ... ], toolbar: [ ... ], simpleUpload: { // The URL that the images are uploaded to. uploadUrl: 'http://example.com', // Enable the XMLHttpRequest.withCredentials belongings. withCredentials: true, // Headers sent along with the XMLHttpRequest to the upload server. headers: { 'X-CSRF-TOKEN': 'CSRF-Token', Dominance: 'Bearer <JSON Web Token>' } } } ) .so( ... ) .take hold of( ... );
# Configuring allowed file types
The allowed file types that can be uploaded should actually exist configured in two places:
- On the client side, in CKEditor 5, restricting image upload through the CKEditor 5 UI and commands.
- On the server side, in your server-side application configuration.
# Client-side configuration
Apply the prototype.upload.types
configuration selection to define the allowed prototype MIME types that can be uploaded to CKEditor 5.
Past default, users are allowed to upload jpeg
, png
, gif
, bmp
, webp
and tiff
files, but yous can customize this behavior to accept, for example, SVG files.
# Server-side configuration
It is up to you to implement any filtering mechanisms on your server in order to restrict the types of images that are immune to be uploaded.
# Server-side configuration
To use this upload adapter, y'all must provide a server–side application that will handle the uploads and communicate with the editor, as described in the following sections.
# Advice protocol
When the paradigm upload process is initiated, the adapter sends a POST
request under config.simpleUpload.uploadUrl
.
You can send additional headers along with the XMLHttpRequest
to the upload server, e.g. to cosign the user, using the config.simpleUpload.headers
object.
If you use the config.simpleUpload.withCredentials
configuration, you may demand some extra HTTP headers for the cross–site asking to work properly.
The responseType
of the request is ever json
. See the Successful upload and Error handling sections to acquire more than.
# Successful upload
If the upload is successful, the server should return:
-
An object containing the
url
property which points to the uploaded image on the server:{ "url": "https://example.com/images/foo.jpg" }
-
Or an object with the
urls
holding, if you lot want to use responsive images and the server supports it:{ "urls": { "default": "https://example.com/images/foo.jpg", "800": "https://example.com/images/foo-800.jpg", "1024": "https://case.com/images/foo-1024.jpg", "1920": "https://example.com/images/foo-1920.jpg" } }
The
"default"
URL will be used in thesrc
attribute of the image in the rich-text editor content. Other URLs volition be used in thesrcset
attribute, assuasive the web browser to select the all-time one for the geometry of the viewport.
The URL(south) in the server response are used:
- To display the prototype during the editing (equally seen past the user in the editor).
- In the editor content saved to the database.
# Error treatment
If something went wrong, the server must return an object that contains the mistake
belongings. This will terminate the upload in the editor, e.g. assuasive the user to select another image if the previous one was too big or did non meet another validation criteria.
If the error
object contains a message
, it volition be passed to the editor notification system and displayed to the user. For the convenience of the users, use clear and possibly specific error messages.
{ "mistake": { "bulletin": "The prototype upload failed considering the image was too big (max ane.5MB)." } }
If the message
property is missing in the error
object, the editor notification system volition display the default "Couldn't upload file: [filename]
." bulletin.
# Upload progress
This upload adapter volition notify users most the file upload progress out–of–the–box.
# What's next?
Check out the comprehensive Epitome upload overview to learn more about different means of uploading images in CKEditor 5.
Run into the Paradigm feature guide to find out more than about handling images in CKEditor v WYSIWYG editor.
# Contribute
The source code of the characteristic is available on GitHub in https://github.com/ckeditor/ckeditor5/tree/master/packages/ckeditor5-upload.
Source: https://ckeditor.com/docs/ckeditor5/latest/features/image-upload/simple-upload-adapter.html
0 Response to "React Ckeditor Filerepository-no-upload-adapter: Upload Adapter Is Not Defined"
Postar um comentário