Skip to content

Commit 1cd349a

Browse files
committed
Remove webkitGetAsEntry method, not standard and supported.
1 parent 9924e0d commit 1cd349a

File tree

3 files changed

+11
-75
lines changed

3 files changed

+11
-75
lines changed

docs/documentation/docs/controls/DragDropFiles.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,13 @@ import { DragDropFiles } from "@pnp/spfx-controls-react/lib/DragDropFiles";
4848

4949
![FilePicker control with grouping](../assets/DragDropFilesSample2.png)
5050

51-
- With the `onDrop` handler you can define a method that returns files and files inside folders that where drag and drop by user.
51+
- With the `onDrop` handler you can define a method that returns files that where drag and drop by user.
5252

53-
**PS: New property "fullPath" was included in file object to allow identify dropped files based on Folders, this allow users to create associated folder path.**
5453

5554
```typescript
5655
private _getDropFiles = (files) => {
5756
for (var i = 0; i < files.length; i++) {
5857
console.log("Filename: " + files[i].name);
59-
console.log("Path: " + files[i].fullPath);
6058
}
6159
}
6260
```

src/controls/dragDropFiles/DragDropFiles.tsx

Lines changed: 8 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -103,87 +103,26 @@ export class DragDropFiles extends React.Component<IDragDropFilesProps, IDragDro
103103

104104
/**
105105
* Add File to Array Files of type File[]
106-
* https://www.meziantou.net/upload-files-and-directories-using-an-input-drag-and-drop-or-copy-and-paste-with.htm
107106
* @param dataTransfer
108107
*/
109108
private getFilesAsync = async (e) => {
110109
const Customfiles = e.dataTransfer;
111110
const items = Customfiles.items;
112-
const Directory = [];
113111
const files: File[] = [];
112+
114113
for (let i = 0; i < items.length; i++) {
115-
const item = items[i];
116-
if (item.kind === "file") {
117-
if (typeof item.webkitGetAsEntry === "function") {
118-
const entry = item.webkitGetAsEntry();
119-
if (entry.isDirectory) {
120-
Directory.push(entry);
121-
}else{
122-
const file = item.getAsFile();
123-
if (file) {
124-
file.fullPath = "";
125-
files.push(file);
126-
}
127-
}
128-
continue;
114+
const item = items[i];
115+
if (item.kind === "file") {
116+
const file = item.getAsFile();
117+
if (file) {
118+
files.push(file);
129119
}
120+
continue;
130121
}
131122
}
132-
if(Directory.length > 0)
133-
{
134-
const entryContent = await this.readEntryContentAsync(Directory);
135-
files.push(...entryContent);
136-
}
137123
return files;
138124
}
139125

140-
// Returns a promise with all the files of the directory hierarchy
141-
/**
142-
*
143-
* @param entry
144-
*/
145-
private readEntryContentAsync = (Directory) => {
146-
return new Promise<File[]>((resolve, reject) => {
147-
let reading = 0;
148-
const contents: File[] = [];
149-
Directory.forEach(entry => {
150-
readEntry(entry, "");
151-
});
152-
153-
function readEntry(entry, path) {
154-
if (entry.isDirectory) {
155-
readReaderContent(entry.createReader());
156-
} else {
157-
reading++;
158-
entry.file(file => {
159-
reading--;
160-
file.fullPath = path;
161-
contents.push(file);
162-
163-
if (reading === 0) {
164-
resolve(contents);
165-
}
166-
});
167-
}
168-
}
169-
170-
function readReaderContent(reader) {
171-
reading++;
172-
173-
reader.readEntries((entries)=> {
174-
reading--;
175-
for (const entry of entries) {
176-
readEntry(entry, entry.fullPath);
177-
}
178-
179-
if (reading === 0) {
180-
resolve(contents);
181-
}
182-
});
183-
}
184-
});
185-
}
186-
187126
/**
188127
* Default React component render method
189128
*/
@@ -216,4 +155,4 @@ export class DragDropFiles extends React.Component<IDragDropFilesProps, IDragDro
216155
</div>
217156
);
218157
}
219-
}
158+
}

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,6 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
484484
private _getDropFiles = (files) => {
485485
for (var i = 0; i < files.length; i++) {
486486
console.log("File name: " +files[i].name);
487-
console.log("Folder Path: " + files[i].fullPath);
488487
}
489488
}
490489

@@ -1201,8 +1200,8 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
12011200
>
12021201

12031202
<Placeholder iconName='BulkUpload'
1204-
iconText='Drag files or folder with files here...'
1205-
description={defaultClassNames => <span className={defaultClassNames}>Drag files or folder with files here...</span>}
1203+
iconText='Drag files here...'
1204+
description={defaultClassNames => <span className={defaultClassNames}>Drag files here...</span>}
12061205
buttonLabel='Configure'
12071206
hideButton={this.props.displayMode === DisplayMode.Read}
12081207
onConfigure={this._onConfigure} />

0 commit comments

Comments
 (0)