4

I tried the official upload command, but it's not working.

This is the CKEditor part

<CKEditor
  placeholder="write"
  editor={ClassicEditor}
  data={this.state.body}
  /*  config={{ckfinder: {
    // Upload the images to the server using the CKFinder QuickUpload command.
    uploadUrl: 'https://example.com/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images&responseType=json'
  }}} */                      
  onReady={(editor) => {
    // You can store the "editor" and use when it is needed.
    console.log("Editor is ready to use!", editor);
  }}
  onChange={(event, editor) => {
    const data = editor.getData();
    this.setState({ body: data });
  }}
/>

After inserting this, I can upload a picture, but a message pops up with the following:

This message pop up

The console displays this error

Access to XMLHttpRequest at 'https://example.com/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images&responseType=json' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. example.com/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images&responseType=json:1

Failed to load resource: net::ERR_FAILED

Cjmarkham
  • 9,484
  • 5
  • 48
  • 81
Anushka Praveen
  • 109
  • 2
  • 13

1 Answers1

2

It looks like you are trying to upload the images to the url "https://example.com/... which, as far as I can tell, is just a default value for the upload configuration, but not meant as a proper URL for file-uploads.

According to the documentation:

To use this upload adapter, you must provide a server–side application that will handle the uploads and communicate with the editor, as described in the following sections.

This means that you need to have access to a server side application to upload your images onto.

If you have that, you can follow the configuration guide here to set the uploadUrl to the correct address.
If you don't have access to a server-side application, you will need to obtain it if you want to use the uploading functionality. A simple suggestion may for example be Cloudinary, which is a Software as a Service provider that can act as an endpoint for your uploaded files. It should be a whole lot easier than trying to create a server app on your own.

consager
  • 237
  • 1
  • 6
  • I haven't a server-side application. How I build it? otherwise, I haven't idea about use uploading functionality – Anushka Praveen Apr 06 '21 at 16:27
  • @AnushkaPraveen Check out Cloudinary, see if you can make sense of that. I've updated the answer to explain it a bit. Otherwise that's a way too big topic for a question here, and honestly a whole profession. – consager Apr 06 '21 at 20:44