Socket
Socket
Sign inDemoInstall

tiptap-extension-upload-image

Package Overview
Dependencies
33
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tiptap-extension-upload-image

The seamless image upload feature with real-time preview. Effortlessly add images to your content while a dynamic placeholder fills in during the upload process. Enhance your editing experience with this intuitive extension.


Version published
Weekly downloads
418
increased by70.61%
Maintainers
1
Install size
34.7 kB
Created
Weekly downloads
 

Readme

Source

Tiptap Extension Upload Image

The seamless image upload feature with real-time preview. Effortlessly add images to your content while a dynamic placeholder fills in during the upload process. Enhance your editing experience with this intuitive extension.

Installation

npm install tiptap-extension-upload-image

Usage

Import package and css
import UploadImage from 'tiptap-extension-upload-image';
import 'tiptap-extension-upload-image/dist/upload-image.min.css';
//Optional
import axios from 'axios';
Register in editor extensions
extensions: [
  StarterKit,
  UploadImage.configure({
    uploadFn: uploadFn
  }),
]
Create a function to upload images

This function is used to upload images using axios or the manager of your preference. It should return a string with the image URL in case of success. In case of an error, it should throw an exception. I am sending this function in the extension's configuration.

const uploadFn = (file) => {
    var formData = new FormData();
    formData.append("image", file);
    return axios.post('/tools/guidelines/media', formData)
    .then((response) => {
        return response.data.url
    })
    .catch((e) => {
        //Optionaly you can send only throw
        throw(e.response.data.error);
    }); 
}
Add command to your menu button

Add this line to your button to open the input type file to select image.

editor.chain().focus().addImage().run()
Styling

You can overwrite the color of spinner.

.image-uploading::before {
    border-top-color: #1e986c;
}

FAQs

Last updated on 26 Aug 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc