agusmakmun / django-markdown-editor

Awesome Django Markdown Editor, supported for Bootstrap & Semantic-UI
GNU General Public License v3.0
823 stars 1.34k forks source link

After version 1.6.26 the setting MARTOR_UPLOAD_URL is ignored #210

Closed lopify closed 8 months ago

lopify commented 1 year ago

On version 1.6.27 and newer the Admin CMS widget ignores the settings field "MARTOR_UPLOAD_URL" and defaults to the Imgur uploader.

Steps to reproduce

  1. Setup a project with a custom uploader
  2. Install Martor v1.6.26 and check that it works
  3. Install Martor v1.6.27 and check that it doesn't works
enjoy-software commented 1 year ago

I think I got the same problem and I solved it. If you configure like this on django version 4.2

urls.py

urlpatterns = [
    ...
    path(
        'api/uploader/', markdown_uploader, name='markdown_uploader_page'
    ),
    path('martor/', include('martor.urls')),
]

settings.py

MARTOR_UPLOAD_URL = '/api/uploader/'  # change to local uploader

Martor upload url will request domain.com/martor/api/uploader.

So you have to modiy path

urls.py

urlpatterns = [
    ...
    # Remember to set it above martor/, django will detect the first matching path.
    path(
        'martor/api/uploader/', markdown_uploader, name='markdown_uploader_page'
    ),
    path('martor/', include('martor.urls')),
]
mvaled commented 1 year ago

I'm getting a 403 error because I don´t use IMGUR. And trying to upload an image results in

{"data":{"error":"Invalid client_id","request":"\/3\/upload.json","method":"POST"},"success":false,"status":403}

Maybe this not taking into account the URL is the actual cause.

kfconsultant commented 11 months ago

I am able to config and save the image in the local storage after downgrading to martor==1.6.26 and update the following files.

`# project urls.py

path('martor/', include('martor.urls')), path('', include('markdowneditor.urls')), `

`# app urls.py

path('api/uploader/', markdown_uploader, name='markdown_uploader_page'),`

`# settings.py MARTOR_ENABLE_CONFIGS = { 'emoji': 'true', # to enable/disable emoji icons. 'imgur': 'true', # to enable/disable imgur/custom uploader. 'mention': 'false', # to enable/disable mention 'jquery': 'true', # to include/revoke jquery (require for admin default django) 'living': 'false', # to enable/disable live updates in preview 'spellcheck': 'false', # to enable/disable spellcheck in form textareas 'hljs': 'true', # to enable/disable hljs highlighting in preview 'imgur': 'true', # to enable/disable imgur uploader/custom uploader. 'mention': 'true', # to enable/disable mention 'jquery': 'true', # to include/revoke jquery (require for admin default django) }

MAX_IMAGE_UPLOAD_SIZE = 5242880 # 50MB

import time MARTOR_UPLOAD_PATH = 'images/uploads/{}'.format(time.strftime("%Y/%m/%d/")) MARTOR_UPLOAD_URL = '/api/uploader/' # change to local uploader `

views.py based on the wiki, we also need to change 2 lines. I am using Django 4.2.7 https://github.com/agusmakmun/django-markdown-editor

if request.method == 'POST' and request.headers.get('X-Requested-With') == 'XMLHttpRequest':`

... if image.size > settings.MAX_IMAGE_UPLOAD_SIZE:`

eriktelepovsky commented 10 months ago

I have the same issue and I've found the bug. This line breaks it:

https://github.com/agusmakmun/django-markdown-editor/blob/af0c347aab1e609428862361460f98e043992d80/martor/urls.py#L35

the view for custom URL is never used and the default markdown_imgur_uploader is applied.

@agusmakmun ?

eriktelepovsky commented 8 months ago

Any update pls?

agusmakmun commented 8 months ago

Hello @eriktelepovsky @lopify @enjoy-software @mvaled @kfconsultant

Thank you for reporting this issue. We just realize that there is bit misconfiguration in this PR #201 Meanwhile we have resolved this issue in the latest version 1.6.38. Please update your package to fix it:

pip3 install martor --upgrade