Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image source address issue in Rest API #489

Open
skilljobs opened this issue Jan 15, 2023 · 4 comments
Open

Image source address issue in Rest API #489

skilljobs opened this issue Jan 15, 2023 · 4 comments

Comments

@skilljobs
Copy link

Suppose images are uploaded from admin.example.com and it stores like "/media/django-summernote/2023-1-11/adsdfsfdf.png"
Not the full URL. So in API, the url is not containing main site. How to fix it?

@uktamjon-komilov
Copy link

I am having the same issue.

@uktamjon-komilov
Copy link

Modified the content before returning the response in the view using util function:

from bs4 import BeautifulSoup

def normalize_html_image_urls(request, content):
    site_url = request.build_absolute_uri('/')
    
    # Use BeautifulSoup to parse the HTML
    soup = BeautifulSoup(content, 'html.parser')
    
    # Find all <img> tags and update their src attribute
    for img in soup.find_all('img'):
        if img.has_attr('src'):
            src = img['src']
            if not src.startswith('http'):
                img['src'] = site_url[:-1] + src
    
    # Convert the updated HTML back to a string
    updated_content = str(soup)

    return updated_content

@mahmudtopu3
Copy link

Well it takes time to do so but I have changed their source code.
https://github.com/summernote/django-summernote/blob/main/django_summernote/views.py
You can override class SummernoteUploadAttachment(UserPassesTestMixin, View):

@uktamjon-komilov
Copy link

Can you give example usage?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants