Comments (6)
you're doing it right.
The editor will give you two params blob
& callback
to addImageBlobHook
.
I guess you already have done uploading blob.
next you can pass uploaded image url to callback like below
...
addImageBlobHook: function(blob, callback) {
var uploadedImageURL = yourUploadingLogicHere(blob);
callback(uploadedImageURL, 'alt text');
}
...
this will replace base64 encode image markdown like this.
[alt text](uploadedImageURLYouHaveFromLogic)
from tui.editor.
More complete example:
...
hooks: {
addImageBlobHook: this.onAddImageBlob(),
},
...
uploadImage(blob) {
let formData = new FormData();
// file in a 'multipart/form-data' request
formData.append(0, blob, blob.name);
return fetch('/upload/image', {
method: 'POST',
body: formData
}).then(response => {
if (response.ok) {
return response.json();
}
throw new Error('Server or network error');
});
};
onAddImageBlob(blob, callback) {
uploadImage(blob)
.then(response => {
if (!response.success) {
throw new Error('Validation error');
}
callback(response.data.url, 'alt text');
}).catch(error => {
console.log(error);
});
};
from tui.editor.
do you have the full code please ?
Hi, @2klm! I published all the code above, but you can try this one too, if the previous code doesn't work for you.
let editorElement = window.document.querySelector('#editor__container');
let editor = new TuiEditor({
el: editorElement,
hooks: {
addImageBlobHook: (blob, callback) => {
let formData = new FormData();
// file in a 'multipart/form-data' request
formData.append(0, blob, blob.name);
fetch('/upload/image', {
method: 'POST',
body: formData
}).then(response => {
if (response.ok) {
return response.json();
}
throw new Error('Server or network error');
}).then(response => {
if (!response.success) {
throw new Error('Validation error');
}
callback(response.data.url, 'alt text');
}).catch(error => {
console.log(error);
});
},
},
});
Be careful, please. This code requires your custom back-end implementation of the images storing and publishing. Example of the server response: {"success":true, "data":{"url":"https://some.domain/img1.png"}}
.
from tui.editor.
Massive thanks @artemmolotov !!
Just a question, is fetch(/upload/image) the link to my PHP script or the destination folder ?
It's link to a your web route or script.
from tui.editor.
I'm closing this. If you have further question, feel free to reopen this.
from tui.editor.
More complete example:
... hooks: { addImageBlobHook: this.onAddImageBlob(), }, ... uploadImage(blob) { let formData = new FormData(); // file in a 'multipart/form-data' request formData.append(0, blob, blob.name); return fetch('/upload/image', { method: 'POST', body: formData }).then(response => { if (response.ok) { return response.json(); } throw new Error('Server or network error'); }); }; onAddImageBlob(blob, callback) { uploadImage(blob) .then(response => { if (!response.success) { throw new Error('Validation error'); } callback(response.data.url, 'alt text'); }).catch(error => { console.log(error); }); };
do you have the full code please ?
from tui.editor.
Related Issues (20)
- Numbered List Issues
- Make base64 encoded images collapsible
- Select in a cell cause error : Uncaught TypeError: Class constructor Selection cannot be invoked without 'new'
- Any fork of this project? HOT 1
- Inserted Image via URL does not show/load on WYSIWYG only editor
- WYSIWYG mode no character escaping
- Support React@18
- enhance the initial table redring
- customHTMLRenderer behavior in Markdown vs WYSIWYG mode
- 표 내부 텍스트 영역 선택 시, 전체 인식 이슈
- getHTML() Method in Toast-UI/Editor Returns Unexpected Value When Editor is Empty HOT 1
- Multiline XML opening tag is not escaped
- 에디터에서 사진 드래그 앤 드랍 막기.
- Specific HTML input breaks WYSIWYG usability
- Does Toast-UI Editor supports dark theme? HOT 1
- [SyntaxError: Unexpected token] on toastui-editor.css
- [ASK] Word Counter and Character
- bold text is not showed correctly in viewer HOT 1
- Heading inside blockquote
- 토스트에디터 버려졌나요? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tui.editor.