
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
@flowjs/ngx-flow
Advanced tools
The purpose of this package is to create a wrapper for Angular for fileupload using [flow.js](https://github.com/flowjs/flow.js).
The purpose of this package is to create a wrapper for Angular for fileupload using flow.js.
https://stackblitz.com/edit/ngx-flow-example
You can also find example source code in the src
folder.
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.
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
.
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>
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.
You can than subscribe to observable of transfers:
<div *ngFor="let transfer of (flow.transfers$ | async).transfers"></div>
After adding files you can begin upload using upload()
method:
<button type="button" (click)="flow.upload()" [disabled]="!(flow.somethingToUpload$ | async)">Start upload</button>
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*/ }
}
You can find it under flow
variable.
<p>Is flowjs supported by the browser? {{flow.flowJs?.support}}</p>
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;
}
}
Add singleFile: true
to your flow config:
<ng-container #flow="flow" [flowConfig]="{target: 'http://localhost:3000/upload', singleFile: true}"></ng-container>
Add flowDirectoryOnly="true"
to your button:
<input type="file" flowButton [flow]="flow.flowJs" flowDirectoryOnly="true" [flowAttributes]="{accept: 'image/*'}" />
Use directive flowSrc
:
<div *ngFor="let transfer of (flow.transfers$ | async).transfers">
<img [flowSrc]="transfer" />
</div>
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();
}
}
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
FAQs
The purpose of this package is to create a wrapper for Angular for fileupload using [flow.js](https://github.com/flowjs/flow.js).
We found that @flowjs/ngx-flow demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.