File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -179,4 +179,28 @@ export class DownloadEntry {
179179 getDataSize ( ) {
180180 return this . dataSize ;
181181 }
182+
183+ // debug
184+ async downloadFile ( ) {
185+ const data = await this . getData ( ) ;
186+
187+ // if it's a blob, convert it to a URL
188+ if ( data instanceof Blob ) {
189+ const url = URL . createObjectURL ( data ) ;
190+ const a = document . createElement ( 'a' ) ;
191+ a . href = url ;
192+ a . download = this . url . split ( '/' ) . pop ( ) || 'download' ;
193+ document . body . appendChild ( a ) ;
194+ a . click ( ) ;
195+ document . body . removeChild ( a ) ;
196+ URL . revokeObjectURL ( url ) ;
197+ } else {
198+ const a = document . createElement ( 'a' ) ;
199+ a . href = 'data:application/octet-stream;base64,' + btoa ( data ) ;
200+ a . download = this . url . split ( '/' ) . pop ( ) || 'download' ;
201+ document . body . appendChild ( a ) ;
202+ a . click ( ) ;
203+ document . body . removeChild ( a ) ;
204+ }
205+ }
182206}
You can’t perform that action at this time.
0 commit comments