diff --git a/README.md b/README.md index 18de629..bd70fcd 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ easyMDE.value('New input for **EasyMDE**'); - **uploadImage**: If set to `true`, enables the image upload functionality, which can be triggered by drag&drop, copy-paste and through the browse-file window (opened when the user click on the *upload-image* icon). Defaults to `false`. - **imageMaxSize**: Maximum image size in bytes, checked before upload (note: never trust client, always check image size at server-side). Defaults to `1024*1024*2` (2Mb). - **imageAccept**: A comma-separated list of mime-types used to check image type before upload (note: never trust client, always check file types at server-side). Defaults to `image/png, image/jpeg`. -- **imageUploadEndpoint**: The endpoint where the images data will be sent, via an asynchronous *POST* request. The server is supposed to save this image, and if it's successful, return a 200-OK HTTP response containing the relative path of the image. No default value. +- **imageUploadEndpoint**: The endpoint where the images data will be sent, via an asynchronous *POST* request. The server is supposed to save this image, and return a 200-OK HTTP response containing: `{"data": {"filePath": ""}}` where *imageFilePath* is the relative path of the image, otherwise, return `{"error": ""}`, where *errorCode* can be `noFileGiven`, `imageTypeNotAllowed`, `imageTooLarge` or `imageImportError` (see *errorMessages* below). No default value. - **imageTexts**: Texts displayed to the user (mainly on the status bar) for the import image feature, where `#image_name#`, `#image_size#` and `#image_max_size#` will replaced by their respective values, that can be used for customization or internationalization: - **sbInit**: Status message displayed initially if `uploadImage` is set to `true`. Defaults to `Attach files by drag and dropping or pasting from clipboard.`. - **sbOnDragEnter**: Status message displayed when the user drags a file to the text area. Defaults to `Drop image to upload it.`. diff --git a/src/js/easymde.js b/src/js/easymde.js index 17a58d3..1bb6fbf 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -1949,8 +1949,8 @@ EasyMDE.prototype.uploadImage = function(file, onSuccess, onError) { onError(fillErrorMessage(self.options.errorMessages.imageImportError)); return; } - if(this.status === 200 && response && response.data && !response.error) { - onSuccess(window.location.origin + '/' + this.responseText); + if(this.status === 200 && response && !response.error && response.data && response.data.filePath) { + onSuccess(window.location.origin + '/' + response.data.filePath); } else { if(response.error && response.error in self.options.errorMessages) { onError(fillErrorMessage(self.options.errorMessages[response.error]));