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

Fix missing file when dragged from browser #294

Open
wants to merge 1 commit into
base: master
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
4 changes: 4 additions & 0 deletions projects/ngx-file-drop/src/lib/dom.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ export interface FileSystemFileEntry extends FileSystemEntry {
isFile: true
file<T>(callback: (file: File) => T): T
}

export function isDataTransferItem(item: DataTransferItem | File): item is DataTransferItem {
return "webkitGetAsEntry" in item && "getAsFile" in item;
}
23 changes: 10 additions & 13 deletions projects/ngx-file-drop/src/lib/ngx-file-drop.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { Subscription, timer } from 'rxjs';

import { NgxFileDropEntry } from './ngx-file-drop-entry';
import { FileSystemDirectoryEntry, FileSystemEntry, FileSystemFileEntry } from './dom.types';
import { FileSystemDirectoryEntry, FileSystemEntry, FileSystemFileEntry, isDataTransferItem } from './dom.types';
import { NgxFileDropContentTemplateDirective } from './ngx-templates.directive';

@Component({
Expand Down Expand Up @@ -204,17 +204,8 @@ export class NgxFileDropComponent implements OnDestroy {
if (!item) {
return;
}
// if ("getAsFile" in item) {
// const file = item.getAsFile();
// if (file) {
// this.addToQueue(
// this.getFakeDropEntry(file)
// );
// return;
// }
// }
if ("webkitGetAsEntry" in item) {
let entry = item.webkitGetAsEntry();
if (isDataTransferItem(item)) {
const entry = item.webkitGetAsEntry();
if (entry) {
if (entry.isFile) {
const toUpload: NgxFileDropEntry = new NgxFileDropEntry(entry.name, entry);
Expand All @@ -225,8 +216,14 @@ export class NgxFileDropComponent implements OnDestroy {
}
return;
}

const file = item.getAsFile();
if (file) {
this.addToQueue(this.getFakeDropEntry(file));
}
return;
}
this.addToQueue(this.getFakeDropEntry((item as File)));
this.addToQueue(this.getFakeDropEntry(item));
}

private checkFiles(items: FileList | DataTransferItemList): void {
Expand Down