mbraak/django-file-form

Keeping directory structure

BoPeng opened this issue · 3 comments

Right now when we upload (e.g. drag and drop)

file1
dir1/file2

we would end up with

file1
file2

and the directory information is lost.

I believe that it is better to keep directory structure and return

file1
dir1/file2

to users. Among other benefits, this would correctly upload for example

README
dir1/README

when README are different.

I'll put this on the todo list.

Something like the following

diff --git a/frontend/src/drop_area.ts b/frontend/src/drop_area.ts
index 5dedcdd..d27e27c 100644
--- a/frontend/src/drop_area.ts
+++ b/frontend/src/drop_area.ts
@@ -20,6 +20,7 @@ const getFilesFromFileSystemEntries = async (
   for await (const entry of entries) {
     if (entry.isFile) {
       const file = await getFileFromFileEntry(entry as FileSystemFileEntry);
+      Object.defineProperty(file, 'path', {value: entry.fullPath.slice(1) })
       result.push(file);
     } else if (entry.isDirectory) {
       const entriesFromDirectory = await getEntriesFromDirectory(
diff --git a/frontend/src/upload_file.ts b/frontend/src/upload_file.ts
index 16f1150..5803eab 100644
--- a/frontend/src/upload_file.ts
+++ b/frontend/src/upload_file.ts
@@ -246,7 +246,7 @@ class UploadFile {
     }

     upload.start();
-    renderer.addNewUpload(filename, uploadIndex);
+    renderer.addNewUpload(file.path, uploadIndex);
     this.uploads.push(upload);
     this.uploadStatuses.push("uploading");
   }
@@ -537,7 +537,7 @@ class UploadFile {
           name: s3Upload.key,
           placeholder: false,
           size: s3Upload.file.size,
-          original_name: s3Upload.file.name
+          original_name: s3Upload.file.path
         } as UploadedFile;
       });

can hack the output, but will not pass yarn lint and only works for s3.

Closing the issue because there has been no activity.