File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -360,13 +360,14 @@ export default class StorageFileApi {
360
360
*
361
361
* @param path The full path and file name of the file to be downloaded. For example `folder/image.png`.
362
362
* @param options.transform Transform the asset before serving it to the client.
363
+ * @param options.stream If set to true, the response will be a ReadableStream. Otherwise, it will be a Blob (default).
363
364
*/
364
- async download (
365
+ async download < Options extends { transform ?: TransformOptions , stream ?: boolean } > (
365
366
path : string ,
366
- options ?: { transform ?: TransformOptions }
367
+ options ?: Options
367
368
) : Promise <
368
369
| {
369
- data : Blob
370
+ data : Options [ 'stream' ] extends true ? ReadableStream : Blob
370
371
error : null
371
372
}
372
373
| {
@@ -385,8 +386,16 @@ export default class StorageFileApi {
385
386
headers : this . headers ,
386
387
noResolveJson : true ,
387
388
} )
388
- const data = await res . blob ( )
389
- return { data, error : null }
389
+
390
+ if ( ! options ?. stream ) {
391
+ const data = await res . blob ( )
392
+ return { data, error : null }
393
+ }
394
+
395
+ return {
396
+ data : res . body ,
397
+ error : null ,
398
+ }
390
399
} catch ( error ) {
391
400
if ( isStorageError ( error ) ) {
392
401
return { data : null , error }
Original file line number Diff line number Diff line change @@ -201,6 +201,16 @@ describe('Object API', () => {
201
201
expect ( res . data ?. type ) . toEqual ( 'text/plain;charset=utf-8' )
202
202
} )
203
203
204
+ test ( 'downloads an object as a stream' , async ( ) => {
205
+ await storage . from ( bucketName ) . upload ( uploadPath , file )
206
+ const res = await storage . from ( bucketName ) . download ( uploadPath , {
207
+ stream : true ,
208
+ } )
209
+
210
+ expect ( res . error ) . toBeNull ( )
211
+ expect ( res . data ) . toBeInstanceOf ( ReadableStream )
212
+ } )
213
+
204
214
test ( 'removes an object' , async ( ) => {
205
215
await storage . from ( bucketName ) . upload ( uploadPath , file )
206
216
const res = await storage . from ( bucketName ) . remove ( [ uploadPath ] )
You can’t perform that action at this time.
0 commit comments