abhaynikam/react-trix-rte

Copy & paste

Closed this issue · 4 comments

Hey,
is there a handler like add attachment for when an image is copied and pasted here..
Please help ASAP..
great work on the library BTW

Same here

@ST2-EV @bnair2001 Trix editor supports drag and drop of attachments or attachment icon to add the attachment. Regarding copy-pasting the images I would need to look into it. Please give me some time.

Thanks for reaching out 🎉

Actually copy pasting is also detected by addAttachment

 handleAttachment = (event) => {
        if (typeof event.attachment.file !== 'undefined'){
            // do what you do with the file
            const data = new FormData()
            data.append('file', event.attachment.file)
            axios.post(`http://localhost:5000/attachments`, data, {
                headers: {
                    'Content-Type': 'multipart/form-data'
                }
            }).then(res => {
                event.attachment.setAttributes({ url: res.data, href: res.data });
                console.log(res.data);
                console.log(this.state);
            })
        }
        else{
        ///add the URL directly to the html
            event.attachment.setAttributes({ url: event.attachment.attachment.previewURL, href: event.attachment.attachment.previewURL });
        }

    }

@ST2-EV That is super cool. Thanks.