downloadAndUploadImages
2.9.5 버전부터 지원합니다.
본문에 있는 이미지 중 URL이 urlPattern과 일치하는 경우, 각 이미지를 다운로드한 후 업로드합니다. 모든 다운로드/업로드가 완료되면 callbackFunc를 호출합니다.
콜백 함수 내에서 getPublishingHtml()을 호출하면 업데이트된 이미지 URL이 포함된 HTML을 반환합니다.
패턴과 일치하는 이미지가 없으면 콜백 함수를 즉시 호출하고 바로 종료합니다. 이 메서드는 에디터 내부의 이미지 URL만 바꾸며, 결과를 HTML에 자동으로 반영하지는 않습니다.
매개변수
| 이름 | 타입 | 설명 |
|---|---|---|
[callbackFunc] | function | (선택 사항) 모든 업로드가 완료된 후 호출되는 콜백 함수 |
[urlPattern] | string | RegExp | (선택 사항) 다운로드할 이미지의 URL 패턴입니다. string은 정규식으로 해석됩니다. 생략하면 editor.download.image.pattern이 사용됩니다. 둘 다 설정되지 않은 경우 오류가 발생합니다. |
예시
// Promise
editor.downloadAndUploadImages(undefined, urlPattern).then(function () {
var html = editor.getPublishingHtml();
});
// Callback
function callback() {
var html = editor.getPublishingHtml();
}
editor.downloadAndUploadImages(callback, urlPattern);
// Usage example — only images from synapeditor.com
var urlPattern = /^https?:\/\/([^\/]+\.)?synapeditor\.com\//;
var callback = function () {
var html = editor.getPublishingHtml();
// Push the updated content back into the editor
editor.openHTML(html);
};
editor.downloadAndUploadImages(callback, urlPattern);