Ends in:
3 DAYS
6 HRS
46 MIN
6 SEC
Ends in:
3 D
6 H
46 M
6 S

Abp Window Service

Download Blob as File

AbpWindowService is an Angular service designed to provide utility methods related to window operations. The service has a downloadBlob function, which is used for downloading blobs as files within the context of a web application.

Usage

To make use of the AbpWindowService in your Angular application, follow the steps below:

Injection

Firstly, ensure that the service is injected into the component or any other Angular entity where you wish to use it.

import { AbpWindowService } from '@abp/ng.core';

constructor(private abpWindowService: AbpWindowService) { }
// or
// private abpWindowService   = inject(AbpWindowService)

Downloading a Blob

Once you have the service injected, you can use the downloadBlob method to initiate the download of blob data as a file. For instance:

someMethod() {
  const myBlob = new Blob(["Hello, World!"], { type: "text/plain" });
  this.abpWindowService.downloadBlob(myBlob, "hello.txt");
}

Permissions & Considerations

Ensure that you have appropriate permissions and user interactions before triggering a download. Since downloadBlob initiates a download programmatically, it's best to tie this action to direct user interactions, such as button clicks, to prevent unexpected behaviors or browser restrictions.

DOCUMENT Token in Service

Angular, being a platform-agnostic framework, is designed to support not only browser-based applications but also other environments like server-side rendering (SSR) through Angular Universal. This design philosophy introduces challenges when accessing global browser-specific objects like window or document directly. To address this, Angular provides a DOCUMENT token that can be used to inject the document object into Angular entities like components and services.

Contributors


Last updated: July 31, 2024 Edit this page on GitHub

Was this page helpful?

Please make a selection.

To help us improve, please share your reason for the negative feedback in the field below.

Please enter a note.

Thank you for your valuable feedback!

Please note that although we cannot respond to feedback, our team will use your comments to improve the experience.

In this document
Community Talks

What’s New with .NET 9 & ABP 9?

21 Nov, 17:00
Online
Watch the Event
Mastering ABP Framework Book
Mastering ABP Framework

This book will help you gain a complete understanding of the framework and modern web application development techniques.

Learn More