diff --git a/src/ocean/utils/WebServiceConnector.ts b/src/ocean/utils/WebServiceConnector.ts index 2aeb274f..23217505 100644 --- a/src/ocean/utils/WebServiceConnector.ts +++ b/src/ocean/utils/WebServiceConnector.ts @@ -2,6 +2,7 @@ import { BodyInit, RequestInit, Response } from 'node-fetch' import fs from 'fs' import { Logger } from '../../utils' import save from 'save-file' +// import { createWriteStream } from 'streamsaver' // eslint-disable-next-line @typescript-eslint/no-var-requires const fetch = require('node-fetch') @@ -101,6 +102,13 @@ export class WebServiceConnector { } } + public async downloadFileBrowser(url: string): Promise { + const anchor = document.createElement('a') + anchor.download = '' + anchor.href = url + anchor.click() + } + private async fetch(url: string, opts: RequestInit): Promise { const result = await fetch(url, opts) if (!result.ok) { diff --git a/src/provider/Provider.ts b/src/provider/Provider.ts index 7ebc2e38..eb6e20f6 100644 --- a/src/provider/Provider.ts +++ b/src/provider/Provider.ts @@ -147,7 +147,9 @@ export class Provider extends Instantiable { consumeUrl += `&signature=${signature}` try { - await this.ocean.utils.fetch.downloadFile(consumeUrl, destination, i) + !destination + ? await this.ocean.utils.fetch.downloadFileBrowser(consumeUrl) + : await this.ocean.utils.fetch.downloadFile(consumeUrl, destination, i) } catch (e) { this.logger.error('Error consuming assets') this.logger.error(e)