Comments (5)
Yeah: #334
from easy-markdown-editor.
Yes, but as I sad in my question the code from #334 is not working.
from easy-markdown-editor.
All code samples I found that has same issue but finally I made it with flask backend with below codes and working right for me:
app.config['ALLOWED_IMAGES_TYPES'] = ['image/png', 'image/jpeg', 'image/jpg']
app.config['IMAGE_UPLOAD_FOLDER'] = 'static/images' # or any other folder you want to use for image uploads
app.config['IMAGE_MAX_SIZE'] = 1024 * 1024 * 2 # 2 MB
@app.route('/imageUpload', methods=['POST'])
def upload_image():
"""
Upload an image to the server and store it to the folder defined in
IMAGE_UPLOAD_FOLDER in flask configuration.
Note that the image folder must be created first and with write access.
:return: A JSON response with the expected format for EasyMDE.
"""
# Check if the request contains the 'image' field in FormData
if 'image' not in request.files:
return jsonify({'error': 'noFileGiven'}), 400 # Bad request
file = request.files['image']
if file.filename == '':
return jsonify({'error': 'noFileGiven'}), 400 # Bad request
if file and file.content_type in app.config['ALLOWED_IMAGES_TYPES']:
if file.content_length > app.config['IMAGE_MAX_SIZE']:
return jsonify({'error': 'fileTooLarge'}), 413 # Payload Too Large
# Generate a safe filename
file_name = f"{file.filename.split('.')[0]}_{len(os.listdir(app.config['IMAGE_UPLOAD_FOLDER']))}.{file.filename.split('.')[-1]}"
file_path = os.path.join(app.config['IMAGE_UPLOAD_FOLDER'], file_name)
# Save the file
file.save(file_path)
# Construct the response in the expected format for EasyMDE
image_url = url_for('static', filename=f'images/{file_name}')
response_data = {
'data': {
'filePath': image_url
}
}
return jsonify(response_data), 200, {'Content-Type': 'application/json'}
else:
return jsonify({'error': 'typeNotAllowed'}), 415 # Unsupported Media Type
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in app.config['ALLOWED_IMAGES_TYPES']
and JavaScript part:
function initializeEasyMDE() {
easyMDE = new EasyMDE({
element: document.getElementById('editor'),
autofocus: true,
spellChecker: false,
uploadImage: true,
imageUploadEndpoint: "imageUpload",
status: [
"words",
"upload-image",
],
toolbar: ["bold", "italic", "heading", "|", "quote", "unordered-list", "ordered-list", "|", "link", "image", "|", "preview", "side-by-side", "fullscreen"],
});
return easyMDE;
}
from easy-markdown-editor.
Related Issues (20)
- Can't build with Typescript 5.x.x HOT 4
- support code mirror 6 HOT 1
- Editor shows strange chars HOT 1
- Node.js EasyMDE upload image HOT 6
- Ctrl+Click to open link
- Can i anyone help me how i fix i am using laravel HOT 1
- Too Generic Image Input Name HOT 4
- IOS keyboard auto-correction not working HOT 1
- Allow .iix file type for images if .iix is in the imageAccept property HOT 1
- LaTeX editor preview
- Emoji support
- How to hide editor, when not visible?
- Memory leak with previewImagesInEditor
- What about text color & styling
- Not a standard link - joplin:// HOT 1
- Side-by-side preview pane rendering with the incorrect height
- Publicly expose _toggleLink/_replaceSelection
- forceSync=true is not working. HOT 1
- Native spell checker isn't working HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from easy-markdown-editor.