Я работаю с https://github.com/yabwe/medium-editor текстовым редактором, и я особенно борюсь с его расширением https://github.com/orthes/medium-editor-insert-plugin.
Мой бэкэнд - Python-Flask
Проблема в том, что я получаю вот эту ошибку:
medium-editor-insert-plugin.js: 1940 - Uncaught TypeError: Невозможно прочитать свойства 'files' из неопределенного
Это метод, который выдает ошибку:
/**
* Callback for successful upload requests.
* https://github.com/blueimp/jQuery-File-Upload/wiki/Options#done
*
* @param {Event} e
* @param {object} data
* @return {void}
*/
Images.prototype.uploadDone = function (e, data) {
$.proxy(this, 'showImage', data.result.files[0].url, data)();
this.core.clean();
this.sorting();
};
Это код jQuery на моей стороне клиента:
var editor = new MediumEditor('.forecast-textarea__editor');
$(function () {
$('.forecast-textarea__editor').mediumInsert({
editor: editor,
addons: {
images: {
uploadScript: null,
deleteScript: null,
captionPlaceholder: 'Type caption for image',
styles: {
slideshow: {
label: '<span class="fa fa-play"></span>',
added: function ($el) {
$el
.data('cycle-center-vert', true)
.cycle({
slides: 'figure'
});
},
removed: function ($el) {
$el.cycle('destroy');
}
}
},
actions: null,
fileUploadOptions: { // (object) File upload configuration. See https://github.com/blueimp/jQuery-File-Upload/wiki/Options
url: '/upload_image', // (string) A relative path to an upload script
acceptFileTypes: /(\.|\/)(gif|jpeg|jpg|png)$/i // (regexp) Regexp of accepted file types
}
}
}
})
});
Это внутренний метод, который отвечает на вызов AJAX:
@bp.route('/upload_image', methods=['GET', 'POST'])
@login_required
def upload_image():
if request.method == 'POST':
files = request.files
print files
print 'hello world, you"re uploading image right NOWWNOWNWOW'
return ('', 204)
Спасибо за помощь!