Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,30 @@ var editor = EditorJS({
*/
uploadByUrl(url){
// your ajax request for uploading
return MyAjax.upload(file).then(() => {
return MyAjax.upload(url).then(() => {
return {
success: 1,
file: {
url: 'https://codex.so/upload/redactor_images/o_e48549d1855c7fc1807308dd14990126.jpg',,
url: 'https://codex.so/upload/redactor_images/o_e48549d1855c7fc1807308dd14990126.jpg',
// any other image data you want to store, such as width, height, color, extension, etc
}
}
})
}
},
/**
* Custom file picker
*/
selectFiles(){
return MyFilePicker.select().then(() => {
return {
success: 1,
file: {
url: 'https://codex.so/upload/redactor_images/o_80beea670e49f04931ce9e3b2122ac70.jpg',
// any other image data you want to store, such as width, height, color, extension, etc
}
};
})
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export default class ImageTool implements BlockTool {
captionPlaceholder: this.api.i18n.t(config.captionPlaceholder ?? 'Caption'),
buttonContent: config.buttonContent,
uploader: config.uploader,
selectFiles: config.selectFiles,
actions: config.actions,
features: config.features || {},
};
Expand Down Expand Up @@ -433,8 +434,10 @@ export default class ImageTool implements BlockTool {
* @param response - uploading server response
*/
private onUpload(response: UploadResponseFormat): void {
if (response.success && Boolean(response.file)) {
this.image = response.file;
if (response.success) {
if (Boolean(response.file)) {
this.image = response.file;
}
} else {
this.uploadingFailed('incorrect response: ' + JSON.stringify(response));
}
Expand Down
5 changes: 5 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ export interface ImageConfig {
uploadByUrl?: (url: string) => Promise<UploadResponseFormat>;
};

/**
* Method to select images using a custom file manager.
*/
selectFiles?: () => Promise<UploadResponseFormat>;

/**
* Additional actions for the tool.
*/
Expand Down
8 changes: 6 additions & 2 deletions src/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ export default class Uploader {
*/
let upload: Promise<UploadResponseFormat>;

// custom uploading
if (this.config.uploader && typeof this.config.uploader.uploadByFile === 'function') {
// custom file select
if (this.config.selectFiles && typeof this.config.selectFiles === 'function') {
upload = this.config.selectFiles();

// custom uploading
} else if (this.config.uploader && typeof this.config.uploader.uploadByFile === 'function') {
const uploadByFile = this.config.uploader.uploadByFile;

upload = ajax.selectFiles({ accept: this.config.types ?? 'image/*' }).then((files: File[]) => {
Expand Down