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

Does quill support image upload? #90

Open
forpizinmind opened this issue May 10, 2014 · 19 comments
Open

Does quill support image upload? #90

forpizinmind opened this issue May 10, 2014 · 19 comments
Labels

Comments

@forpizinmind
Copy link

Hi,
Quill is an excellent editor!!
May I know whether quill support image upload?any demo server side script?
Many thanks.

@jhchen jhchen added the feature label May 11, 2014
@alexeckermann
Copy link

Would I be right in thinking that this would be a module? Since the server side, upload presentation and execution varies wildly from application to application.

Could it be a third-party module that we include rather than the core project deciding how uploads should be handled? Then its up to the developer to pick which one will work for them.

After using ckeditor for a long time I really like how simple quill is and would hate to see it turn into a behemoth like ckeditor.

@jhchen
Copy link
Member

jhchen commented Nov 16, 2014

The hosting files part is definitely outside of Quill's scope but I think it could do more than it currently does. For example, one possibility is you just supply Quill with a server endpoint for uploads but the UI for drag and drop and choosing a file for upload could be handled by Quill (it would be organized as a module but one of the officially supported ones). A guide or example on using imgur or s3 for this could be provided as well.

@nburwell
Copy link

👍 to have a supported module for the UI. I'm looking to move over to Quill and we already have server-side image upload support (for a custom plugin to Ext's HTMLEditor) and would love to have that support in QuillJS too!

@getup8
Copy link

getup8 commented Nov 11, 2015

@alexcroox
Copy link

That's more of an image import from remote URL than image upload.

@swim
Copy link

swim commented Mar 22, 2016

Here's some basic integration with the Dropzone.js library https://github.com/swim/quill-dropzone - please note; this does not handle any server side code.

@jhchen
Copy link
Member

jhchen commented Sep 15, 2016

I'm deleting all +1s so the comments can be easier to find. Please use the reaction feature to show support.

@lms-sam
Copy link

lms-sam commented Jun 5, 2017

@getup8 page is missing https://github.com/quilljs/quill/blob/develop/src/modules/image-tooltip.js

@ycjcl868
Copy link

ycjcl868 commented Jan 7, 2018

request entity will be too large when using Base64 encoding the image,

image

@MarcGodard
Copy link

Images should just be handled with a callback function.

onImage(data) {
     return server.upload(data)
           .then(imageUrl => {
                  return imageUrl
     })
}

@daslicht
Copy link

Images should just be handled with a callback function.

onImage(data) {
     return server.upload(data)
           .then(imageUrl => {
                  return imageUrl
     })
}

how does that work together with the default image upload from the snow theme ? please

@MarcGodard
Copy link

@daslicht This is my code, lots there that you do not need, but it should be easy to figure out.

let Image = Quill.import('formats/image')
    Image.className = 'img-responsive'
    Quill.register(Image, true)

    quill.getModule('toolbar').addHandler('image', () => {
      const input = document.createElement('input')
      input.setAttribute('type', 'file')
      input.setAttribute('accept', 'image/*')
      input.click()

      input.onchange = () => {
        const file = input.files[0]
        const reader = new window.FileReader()
        reader.readAsDataURL(file)

        reader.addEventListener('load', () => {
          let imageUpload = new Upload({
            uri: reader.result,
            type: file.type,
            size: file.size,
            fileName: file.name,
            source: 'text editor'
          })
          imageUpload
            .save()
            .then(data => {
              const range = quill.getSelection()
              quill.insertEmbed(range.index, 'image', env.siteUrl + '/api/upload/' + data.fileName)
            })
        }, false)
      }
    })

@kyrofa
Copy link

kyrofa commented Jun 28, 2019

What about when the image is deleted? That needs to be handled somehow server-side as well.

@MarcGodard
Copy link

@kyrofa I just don't deal with that yet. Space is cheap. I do track when images were last used, so worst case if space gets tight, I can just delete images that haven't been accessed in years.

@ydang204
Copy link

I face another issue after handling upload images to the server instead of generating a base64 string.
I have 1 input to create title of news and quill to create the body. After changing the way save the image, I can not type on the title input twice

@sucrose
Copy link

sucrose commented Jan 2, 2020

I face another issue after handling upload images to the server instead of generating a base64 string.
I have 1 input to create title of news and quill to create the body. After changing the way save the image, I can not type on the title input twice

Sounds like you have a front-end GUI bug, try opening a new ticket or review your console for any errors.

@codecret
Copy link

I face another issue after handling upload images to the server instead of generating a base64 string. I have 1 input to create title of news and quill to create the body. After changing the way save the image, I can not type on the title input twice

did you solve it , can we upload our image to a cloud server like cloudinary or firebase then use it in our rich text (in the same order)

@devmaxime
Copy link

devmaxime commented Jul 2, 2024

I face another issue after handling upload images to the server instead of generating a base64 string. I have 1 input to create title of news and quill to create the body. After changing the way save the image, I can not type on the title input twice

did you solve it , can we upload our image to a cloud server like cloudinary or firebase then use it in our rich text (in the same order)

I have made a server-side script to upload to Firebase Storage as I was looking for the same answer you never found out here.

In your function that receive the content from quill editor (server-side)

```
const imageRegex = /<img src="data:image\/[^;]+;base64,([^"]+)"[^>]*>/g;
    let match;
    let updatedContent = content;

    // Extract all base64 images
    const matches = [];
    while ((match = imageRegex.exec(content)) !== null) {
        matches.push(match);
    }

    if (matches.length === 0) {
        return content;
    }

    // Process each base64 image and replace it with the uploaded image URL
    for (const match of matches) {
        const base64Image = match[1];
        checkImageSize(base64Image); // Check image size before processing
        const imageUrl = await uploadImageToStorage(base64Image);
        updatedContent = updatedContent.replace(match[0], `<img src="${imageUrl}" />`);
    }
```

If you need it as well, here is my uploadImageToStorage function

```
const uploadImageToStorage = async (base64Image: string): Promise<string> => {
    try {
        const buffer = Buffer.from(base64Image, 'base64');
        const fileName = `articles/${Date.now()}.jpg`;
        const file = admin.storage().bucket().file(fileName);
      
        await file.save(buffer, {
          contentType: 'image/jpeg',
        });
      
        // Return the public URL of the uploaded file
        return `https://storage.googleapis.com/${admin.storage().bucket().name}/${fileName}`;
    } catch (error) {
        logger.error('Error uploading image to storage:', error);
        throw new Error('Error uploading image to storage: ' + error);
    }
};
```

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

Successfully merging a pull request may close this issue.