diff --git a/README.md b/README.md index d628d40..01f6d95 100644 --- a/README.md +++ b/README.md @@ -266,6 +266,19 @@ Example: this.imageLoaderConfig.enableFallbackAsPlaceholder(true); ``` --- +#### setFileTransferOptions(options: any) +Set options for FileTransfer plugin to use. If you would like to set a value for the `trustAllHosts` param, you can add it to the options object. + +Example: +```ts +this.imageLoaderConfig.setFileTransferOptions({ + trustAllHosts: true, // defaults to false + headers: { + Authorization: 'Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA==' + } +}); +``` +--- # Preloading images ```typescript diff --git a/src/providers/image-loader-config.ts b/src/providers/image-loader-config.ts index 5ec5fb2..c5cf19a 100644 --- a/src/providers/image-loader-config.ts +++ b/src/providers/image-loader-config.ts @@ -35,6 +35,10 @@ export class ImageLoaderConfig { spinnerColor: string; + fileTransferOptions: any = { + trustAllHosts: false + }; + private _cacheDirectoryName: string = 'image-loader-cache'; set cacheDirectoryName(name: string) { @@ -182,4 +186,12 @@ export class ImageLoaderConfig { this.spinnerColor = color; } + /** + * Set options for the FileTransfer plugin + * @param options + */ + setFileTransferOptions(options: { trustAllHosts: boolean; [key: string]: any; }): void { + this.fileTransferOptions = options; + } + } diff --git a/src/providers/image-loader.ts b/src/providers/image-loader.ts index 7c6cafe..3740721 100644 --- a/src/providers/image-loader.ts +++ b/src/providers/image-loader.ts @@ -241,7 +241,7 @@ export class ImageLoader { // take the first item from queue const currentItem: QueueItem = this.queue.splice(0, 1)[0]; - + // create FileTransferObject instance if needed // we would only reach here if current jobs < concurrency limit // so, there's no need to check anything other than the length of @@ -266,7 +266,7 @@ export class ImageLoader { const localPath = this.file.cacheDirectory + this.config.cacheDirectoryName + '/' + this.createFileName(currentItem.imageUrl); - transfer.download(currentItem.imageUrl, localPath) + transfer.download(currentItem.imageUrl, localPath, Boolean(this.config.fileTransferOptions.trustAllHosts), this.config.fileTransferOptions) .then((file: FileEntry) => { if (this.shouldIndex) { this.addFileToIndex(file).then(this.maintainCacheSize.bind(this));