Skip to content

Added .file() returning a Blob instead of Collection #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/content/en/api/query-builder-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,21 @@ await Model.$find(1)

<alert type="info">These `$`-prefixed convenience methods always return the requested content.
They handle and unwrap responses within "data".</alert>

## `file`
- Returns: `Binary`

Execute the query with $http.responseType as `blob` and returns a binary

```js
// get the blob
const data = await Model.file()

// force file download
const url = window.URL.createObjectURL(new Blob([data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'model.xlsx'); //or any other extension
document.body.appendChild(link);
link.click();
```
8 changes: 8 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,14 @@ export class Model extends StaticModel {
* @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#retrieving-a-list-of-records|Building the Query}
*/
get (): QueryPromise<this[]>

/**
* Execute the query and get all results.
*
* @see {@link https://robsontenorio.github.io/vue-api-query/api/query-builder-methods#file|API Reference}
* @see {@link https://robsontenorio.github.io/vue-api-query/building-the-query#retrieving-a-list-of-records|Building the Query}
*/
file (): QueryPromise<BlobPart[]>

/**
* Execute the query and get all results.
Expand Down
Loading