diff --git a/src/index.ts b/src/index.ts index c42162a1..0c367629 100644 --- a/src/index.ts +++ b/src/index.ts @@ -99,8 +99,8 @@ export default class ImageTool implements BlockTool { endpoints: config.endpoints, additionalRequestData: config.additionalRequestData, additionalRequestHeaders: config.additionalRequestHeaders, - field: config.field || 'image', - types: config.types || 'image/*', + field: config.field, + types: config.types, captionPlaceholder: this.api.i18n.t(config.captionPlaceholder ? config.captionPlaceholder: 'Caption'), buttonContent: config.buttonContent, uploader: config.uploader, diff --git a/src/types/types.ts b/src/types/types.ts index 53945d7c..f4b564f6 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -117,12 +117,12 @@ export interface ImageConfig { /** * Field name for the uploaded image. */ - field: string; + field?: string; /** * Allowed mime-types for the uploaded image. */ - types: string; + types?: string; /** * Placeholder text for the caption field. diff --git a/src/uploader.ts b/src/uploader.ts index 006b4690..d7348078 100644 --- a/src/uploader.ts +++ b/src/uploader.ts @@ -72,7 +72,7 @@ export default class Uploader { // custom uploading if (this.config.uploader && typeof this.config.uploader.uploadByFile === 'function') { const uploadByFile = this.config.uploader.uploadByFile; - upload = ajax.selectFiles({ accept: this.config.types}).then((files: File[]) => { + upload = ajax.selectFiles({ accept: this.config.types || 'image/*'}).then((files: File[]) => { preparePreview(files[0]); const customUpload = uploadByFile(files[0]); @@ -89,12 +89,12 @@ export default class Uploader { upload = ajax.transport({ url: this.config.endpoints.byFile, data: this.config.additionalRequestData, - accept: this.config.types, + accept: this.config.types || 'image/*', headers: new Headers(this.config.additionalRequestHeaders as Record), beforeSend: (files: File[]) => { preparePreview(files[0]); }, - fieldName: this.config.field, + fieldName: this.config.field || 'image', }).then((response: any) => response.body); } @@ -181,7 +181,7 @@ export default class Uploader { */ const formData = new FormData(); - formData.append(this.config.field, file); + formData.append(this.config.field || 'image', file); if (this.config.additionalRequestData && Object.keys(this.config.additionalRequestData).length) { Object.entries(this.config.additionalRequestData).forEach(([name, value]: [string, any]) => {