File tree Expand file tree Collapse file tree 4 files changed +54
-0
lines changed Expand file tree Collapse file tree 4 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -363,3 +363,21 @@ await Model.$find(1)
363363
364364<alert type =" info " >These ` $ ` -prefixed convenience methods always return the requested content.
365365They handle and unwrap responses within "data".</alert >
366+
367+ ## ` file `
368+ - Returns: ` Binary `
369+
370+ Execute the query with $http.responseType as ` blob ` and returns a binary
371+
372+ ``` js
373+ // get the blob
374+ const data = await Model .file ()
375+
376+ // force file download
377+ const url = window .URL .createObjectURL (new Blob ([data]));
378+ const link = document .createElement (' a' );
379+ link .href = url;
380+ link .setAttribute (' download' , ' model.xlsx' ); // or any other extension
381+ document .body .appendChild (link);
382+ link .click ();
383+ ```
Original file line number Diff line number Diff line change @@ -733,6 +733,14 @@ export class Model extends StaticModel {
733733 */
734734 get ( ) : QueryPromise < this[ ] >
735735
736+ /**
737+ * Execute the query and get all results.
738+ *
739+ * @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#file|API Reference }
740+ * @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#retrieving-a-list-of-records|Building the Query }
741+ */
742+ file ( ) : QueryPromise < BlobPart [ ] >
743+
736744 /**
737745 * Execute the query and get all results.
738746 *
Original file line number Diff line number Diff line change @@ -469,6 +469,28 @@ export default class Model extends StaticModel {
469469 } )
470470 }
471471
472+ file ( ) {
473+ let base = this . _fromResource || `${ this . baseURL ( ) } /${ this . resource ( ) } `
474+ base = this . _customResource
475+ ? `${ this . baseURL ( ) } /${ this . _customResource } `
476+ : base
477+
478+ let url = `${ base } ${ this . _builder . query ( ) } `
479+
480+ return this . request (
481+ this . _reqConfig ( {
482+ url,
483+ method : 'GET' ,
484+ responseType : 'blob' ,
485+ headers : {
486+ accept : 'application/octet-stream'
487+ }
488+ } )
489+ ) . then ( ( response ) => {
490+ return response . data
491+ } )
492+ }
493+
472494 $get ( ) {
473495 return this . get ( ) . then ( ( response ) => response . data || response )
474496 }
Original file line number Diff line number Diff line change @@ -146,6 +146,12 @@ export default class StaticModel {
146146 return self . get ( )
147147 }
148148
149+ static file ( ) {
150+ let self = this . instance ( )
151+
152+ self . file ( )
153+ }
154+
149155 static all ( ) {
150156 let self = this . instance ( )
151157
You can’t perform that action at this time.
0 commit comments