简体   繁体   English

jQuery 文件上传插件:是否可以保留上传文件夹的结构?

[英]jQuery File Upload Plugin: Is possible to preserve the structure of uploaded folders?

I am trying this plugin ( https://github.com/blueimp/jQuery-File-Upload ) and interesting in folder upload.我正在尝试这个插件( https://github.com/blueimp/jQuery-File-Upload )并且在文件夹上传中很有趣。

I wonder if the plugin is able to preserve the structure of uploaded subfolders (= uploading 1 folder with 3 subfolder, each containing several files)?我想知道该插件是否能够保留上传的子文件夹的结构(= 上传 1 个文件夹和 3 个子文件夹,每个文件夹包含多个文件)?

This should be possible at webkit browsers using drag-and-drop .dataTransfer object at drop event;这应在可能webkit使用拖放和拖放浏览器.dataTransfer对象在drop事件; .webkitGetAsEntry() ; .webkitGetAsEntry() ; webkitRequestFileSystem getDirectory() to create directory having same name as uploaded folder, .createReader() on DirectoryEntry , readEntries() to iterate entries in directory, call .copyTo() for each FileEntry with destination being created directory having uploaded directory name. webkitRequestFileSystem getDirectory()创建与上传文件夹同名的目录, .createReader()DirectoryEntryreadEntries()迭代目录中的条目,为每个FileEntry调用.copyTo()目标正在创建的目录具有上传的目录名称。

The folder should now be accesible using either webkitRequestFileSystem() , then calling .getDirectory() with directory name as first parameter and empty options object {} as second parameter.现在应该可以使用webkitRequestFileSystem()访问该文件夹,然后使用目录名称作为第一个参数和空选项对象{}作为第二个参数调用.getDirectory()

Alternatively, can access folder from actual user filesystem at chrome or chromium profile folder using file manager gui or command line interface.或者,可以使用文件管理器 gui 或命令行界面从 chrome 或chromium 配置文件文件夹中的实际用户文件系统访问文件夹。 Or, create a local script to copy folders in File System to another directory, and rename folders to original names of folders that were uploaded.或者,创建一个本地脚本将File System中的File System夹复制到另一个目录,并将文件夹重命名为已上传文件夹的原始名称。 The folder and file paths are not adjusted, only the folder names.不调整文件夹和文件路径,只调整文件夹名称。

is able to preserve the structure of uploaded subfolders (= uploading 1 folder with 3 subfolder, each containing several files)?是否能够保留上传的子文件夹的结构(= 上传 1 个文件夹和 3 个子文件夹,每个文件夹包含多个文件)?

At file manager the folder would not be named the same as uploaded directory, though should retain folder and file structure.在文件管理器中,文件夹的名称不会与上传的目录相同,但应保留文件夹和文件结构。 The folder should be located at last folder in File System at chrome profile folder, before Origins folder.该文件夹应位于File System中 chrome 配置文件文件夹中的最后一个文件夹,在Origins文件夹之前。 See also How to Write in file (user directory) using JavaScript?另请参阅如何使用 JavaScript 写入文件(用户目录)?

function errorHandler(e) {
  console.log(e)
}

function handleFiles(e) {
  console.log("file", file)
}

function handleDrop(event) {
  var dt = event.dataTransfer;
  for (var i = 0; i < event.dataTransfer.items.length; i++) {
    var entry = dt.items[i].webkitGetAsEntry();
    if (entry.isFile) {
      console.log("isFile", entry.isFile, entry);
      entry.file(handleFiles);
    } else if (entry.isDirectory) {
      console.log("isDirectory", entry.isDirectory, entry);
      window.webkitRequestFileSystem(window.TEMPORARY, 1024 * 1024
      , function(fs) {
        // create directory with uploaded directory name
        fs.root.getDirectory(entry.name, {
          create: true
        }, function(dirEntry) {
          // read folders, files in uploaded directory
          var reader = entry.createReader();
          reader.readEntries(function(entries) {
            entries.forEach(function(file) {
              // copy files to new directory
              file.copyTo(dirEntry);
              console.log("file:", file, "\ncopied to directory:", dirEntry)
            })
          })
        }, errorHandler)
      }, errorHandler)
    }
  }
}

plnkr http://plnkr.co/edit/oUIhwUc3CDxI64SrvxIh?p=preview plnkr http://plnkr.co/edit/oUIhwUc3CDxI64SrvxIh?p=preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM