Skip to content
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

feat(file-picker): implement pickDirectory method #791

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
13 changes: 12 additions & 1 deletion src/app/modules/file-picker/file-picker.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
<ion-checkbox formControlName="readData"></ion-checkbox>
</ion-item>
</form>
<ion-button expand="block" (click)="pickFile()">Pick Files</ion-button>
<ion-button expand="block" (click)="pickDirectory()"
>Pick Directory</ion-button
>
<ion-button expand="block" (click)="pickFiles()">Pick Files</ion-button>
<ion-button expand="block" (click)="pickImages()">Pick Images</ion-button>
<ion-button expand="block" (click)="pickMedia()">Pick Media</ion-button>
<ion-button expand="block" (click)="pickVideos()">Pick Videos</ion-button>
Expand Down Expand Up @@ -99,6 +102,14 @@
<ion-label position="fixed">Width</ion-label>
<ion-input type="text" readonly [value]="file.width"></ion-input>
</ion-item>
<ion-item>
<ion-label position="fixed">Modified At</ion-label>
<ion-input
type="text"
readonly
[value]="file.modifiedAt | date:'long'"
></ion-input>
</ion-item>
<img *ngIf="file.path" [src]="convertPathToWebPath(file.path)" />
</ion-card-content>
</ion-card>
Expand Down
17 changes: 16 additions & 1 deletion src/app/modules/file-picker/file-picker.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component } from '@angular/core';
import { UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
import { Capacitor } from '@capacitor/core';
import { Filesystem } from '@capacitor/filesystem';
import { FilePicker, PickedFile } from '@capawesome/capacitor-file-picker';

@Component({
Expand All @@ -22,7 +23,21 @@ export class FilePickerPage {

constructor(private readonly domSanitizer: DomSanitizer) {}

public async pickFile(): Promise<void> {
public async pickDirectory(): Promise<void> {
await Filesystem.requestPermissions();
const { path } = await FilePicker.pickDirectory();
const { files } = await Filesystem.readdir({ path });
this.files = files.map(file => {
return {
name: file.name,
path: file.uri,
mimeType: file.type,
size: file.size,
};
});
}

public async pickFiles(): Promise<void> {
const types = this.formGroup.get('types')?.value || [];
const multiple = this.formGroup.get('multiple')?.value || false;
const readData = this.formGroup.get('readData')?.value || false;
Expand Down