@flowjs/ngx-flow

中文文档
21.0.0发布于 2026/05/24MITTypeScriptES Module近 30 天下载 6.1万

The purpose of this package is to create a wrapper for Angular for fileupload using flow.js.

原始使用文档
文档目录13 节
  1. Demo
  2. Roadmap
  3. Install
  4. How to use
  5. How does transfers$ data look like?
  6. FAQ
  7. I need access to flow.js object
  8. I see flickering when upload is in progress
  9. I need just a single file
  10. I want to upload whole directory
  11. I want to display image which is going to be uploaded
  12. How to trigger upload right after picking the file?
  13. Development

NgxFlow

The purpose of this package is to create a wrapper for Angular for fileupload using flow.js.

Build Status Test Coverage Maintainability code style: prettier

Demo

https://stackblitz.com/edit/ngx-flow-example

You can also find example source code in the src folder.

Roadmap

  • ✅ upload single file
  • ✅ upload multiple files
  • ✅ queue management
  • ✅ error handling
  • ✅ pause / resume upload
  • ✅ cancel upload, cancel all uploads
  • ✅ upload progress
  • ✅ file / directory restrictions
  • ✅ drag & drop
  • ✅ display uploaded image
  • ✅ tests
  • ✅ upload right after selecting file
  • ✅ run tests using TravisCI
  • ✅ demo using Stackblitz
  • ✅ support for server side rendering

Install

npm install @flowjs/flow.js @flowjs/ngx-flow

Import in your module:

import { NgxFlowModule, FlowInjectionToken } from '@flowjs/ngx-flow';
import Flow from '@flowjs/flow.js';

@NgModule({
  imports: [NgxFlowModule],
  providers: [
    {
      provide: FlowInjectionToken,
      useValue: Flow
    }
  ]
})
export class AppModule

We use dependecy injection to provide flow.js library.

How to use

  1. Start up server. There is a server example taken from flow.js here in server directory. In this repo you can run it using npm run server.

  2. First you need to initialize ngx-flow directive and export it as for example flow variable:

    <ng-container #flow="flow" [flowConfig]="{target: 'http://localhost:3000/upload'}"></ng-container>
    
  3. Now you can use either directive flowButton for select file dialog:

    <input type="file" flowButton [flow]="flow.flowJs" [flowAttributes]="{accept: 'image/*'}" />
    

    Or flowDrop for drag&drop feature:

    <div class="drop-area" flowDrop [flow]="flow.flowJs"></div>
    

    For both you have to pass [flow]=flow.flowJs where flow is template variable exported in step 1.

  4. You can than subscribe to observable of transfers:

    <div *ngFor="let transfer of (flow.transfers$ | async).transfers"></div>
    
  5. After adding files you can begin upload using upload() method:

    <button type="button" (click)="flow.upload()" [disabled]="!(flow.somethingToUpload$ | async)">Start upload</button>
    

How does transfers$ data look like?

Observable flow.transfers$ emits state in form:

{
  totalProgress: 0.5,
  transfers: [
    {
      name: "somefile.txt",
      flowFile: FlowFile,
      progress: number,
      error: boolean,
      paused: boolean,
      success: boolean,
      complete: boolean,
      currentSpeed: number,
      averageSpeed: number,
      size: number,
      timeRemaining: number,
    },
    {
      name: "uploading.txt",
      flowFile: FlowFile,
      progress: 0.5,
      error: false,
      paused: false,
      success: false,
      complete: false,
      currentSpeed: number,
      averageSpeed: number,
      size: number,
      timeRemaining: number,
    },
    {
      name: "failed-to-upload.txt",
      flowFile: FlowFile,
      progress: number,
      error: true,
      paused: false,
      success: false,
      complete: true,
      currentSpeed: number,
      averageSpeed: number,
      size: number,
      timeRemaining: number,
    }
    {
      name: "uploaded.txt",
      flowFile: FlowFile,
      progress: number,
      error: false,
      paused: false,
      success: true,
      complete: true,
      currentSpeed: number,
      averageSpeed: number,
      size: number,
      timeRemaining: number,
    }
  ],
  flow: { /* flow.js instance*/ }
}

FAQ

I need access to flow.js object

You can find it under flow variable.

<p>Is flowjs supported by the browser? {{flow.flowJs?.support}}</p>

I see flickering when upload is in progress

Use trackBy for ngFor:

<div *ngFor="let transfer of (flow.transfers$ | async).transfers; trackBy: trackTransfer"></div>
export class AppComponent {
  trackTransfer(transfer: Transfer) {
    return transfer.id;
  }
}

I need just a single file

Add singleFile: true to your flow config:

<ng-container #flow="flow" [flowConfig]="{target: 'http://localhost:3000/upload', singleFile: true}"></ng-container>

I want to upload whole directory

Add flowDirectoryOnly="true" to your button:

<input type="file" flowButton [flow]="flow.flowJs" flowDirectoryOnly="true" [flowAttributes]="{accept: 'image/*'}" />

I want to display image which is going to be uploaded

Use directive flowSrc:

<div *ngFor="let transfer of (flow.transfers$ | async).transfers">
  <img [flowSrc]="transfer" />
</div>

How to trigger upload right after picking the file?

Subscribe to events$. NgxFlow listens for these events: filesSubmitted, fileRemoved, fileRetry, fileProgress, fileSuccess, fileError of flow.js. Event fileSubmitted is fired when user drops or selects a file.

export class AppComponent implements AfterViewInit, OnDestroy {
  @ViewChild('flow')
  flow: FlowDirective;

  autoUploadSubscription: Subscription;

  ngAfterViewInit() {
    this.autoUploadSubscription = this.flow.events$.subscribe((event) => {
      if (event.type === 'filesSubmitted') {
        this.flow.upload();
      }
    });
  }

  ngOnDestroy() {
    this.autoUploadSubscription.unsubscribe();
  }
}

Development

npm run build - builds the library into dist folder

After that you can publish to npm repository from dist folder:

cd dist/ngx-flow
npm publish

版本与发布记录

@flowjs/ngx-flow 共发布 25 个版本,首次发布于 2018/09/20;过去 12 个月发布了 1 个版本。

版本发布日期距今
21.0.0latest2026/05/245 个月前
20.0.22025/07/171.3 年前
20.0.12025/07/161.3 年前
20.0.02025/07/161.3 年前
19.0.02025/02/211.7 年前
18.0.12024/11/012 年前

关于 @flowjs/ngx-flow 的常见问题

@flowjs/ngx-flow 是什么?

The purpose of this package is to create a wrapper for Angular for fileupload using flow.js.

如何安装 @flowjs/ngx-flow?

在项目目录运行 npm install @flowjs/ngx-flow,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@angular/common(^21.0.0)、@angular/core(^21.0.0)、@flowjs/flow.js(^2.14.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@flowjs/ngx-flow 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@flowjs/ngx-flow 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@flowjs/ngx-flow 可以商用吗?

@flowjs/ngx-flow 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@flowjs/ngx-flow 的下载量有多少?

根据 npm 官方下载统计,@flowjs/ngx-flow 在 2026/10/15 – 2026/11/13 这 30 天内被下载 61,318 次,日均约 2,044 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flowjs/ngx-flow 还在维护吗?

最新版本 21.0.0 发布于 2026/05/24(5 个月前);至今共发布 25 个版本,其中过去 12 个月发布了 1 个;首次发布于 2018/09/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。