Ionaru / Ionaru/easy-markdown-editor

EasyMDE: The server did not return a valid json.

Open
#227 2 comments 0 reactions 0 assignees View on GitHub
Question
Dominant language
JavaScript
Stars
3.1k
Forks
363
PR merge metrics
No merged PRs in 30d

Description

I got this message after uploading an image:

````EasyMDE: The server did not return a valid json.````

My code is the following:
```js
new EasyMDE({
element: document.getElementById('EasyMDE_field'),
hideIcons: ['image'],
showIcons: ['upload-image'],
imageUploadEndpoint: "https://domain.de/CMS/functions/img_upload.php"
});
```
and in the img_upload.php:
```php
if(isset($_FILES['image'])) {
$uploaddir = '../data/';
$uploadfile = $uploaddir . basename($_FILES['image']['name']);

if(!is_uploaded_file($_FILES['image']['tmp_name'])) {
echo json_encode(array('error'=>'importError'));
echo "can't upload";
}
if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) {
echo json_encode(array('data'=> array('filePath'=>$upload_json)));
}
}
```
The images are getting uploaded, but there will be no link insert in the Textfield, instead i got an error message
and the json code loos so:
````json
{"data":{"filePath":"..\/data\/image.png"}}
````

Contributor guide

Open the contributing guide

Research direction

Start with EasyMDE's image-upload handling and the shown img_upload.php endpoint, comparing the response produced by the upload path with the JSON shape returned in the report. Reproduce an image upload, check the complete server response, and consider the work done when the editor accepts it and inserts the image link.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, php
Domain
api, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.