downloadAndUploadImages

Release 2.9.5+

For images in the body whose URLs match urlPattern, downloads each image and then uploads it. When all downloads/uploads finish, calls callbackFunc.

Within the callback, calling getPublishingHtml() returns the HTML with the updated image URLs.

If no images match the pattern, the callback is invoked immediately and the function returns. This only rewrites the editor's internal image URLs — it does NOT automatically push the result back into the HTML.

Parameters

NameTypeDescription
[callbackFunc]function(optional) Callback after all uploads finish
urlPatternRegExpURL pattern of images to download

Example

// 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);