jQuery File Upload Plugin:是否可以保留上传文件夹的结构? [英] jQuery File Upload Plugin: Is possible to preserve the structure of uploaded folders?

查看:25
本文介绍了jQuery File Upload Plugin:是否可以保留上传文件夹的结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试这个插件(https://github.com/blueimp/jQuery-File-上传)和有趣的文件夹上传.

I am trying this plugin (https://github.com/blueimp/jQuery-File-Upload) and interesting in folder upload.

我想知道插件是否能够保留上传子文件夹的结构(= 上传 1 个文件夹和 3 个子文件夹,每个子文件夹包含多个文件)?

I wonder if the plugin is able to preserve the structure of uploaded subfolders (= uploading 1 folder with 3 subfolder, each containing several files)?

推荐答案

这应该可以在 webkit 浏览器上使用拖放 .dataTransfer 对象在 drop 事件;.webkitGetAsEntry();webkitRequestFileSystem getDirectory() 创建与上传文件夹同名的目录,.createReader() on DirectoryEntry , readEntries() 来迭代目录中的条目,为每个 FileEntry 调用 .copyTo() 并创建目标目录并上传目录名称.

This should be possible at webkit browsers using drag-and-drop .dataTransfer object at drop event; .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() 并使用目录名称作为第一个参数和空选项对象 {} 作为第二个参数.

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.

或者,可以使用文件管理器 gui 或命令行界面从 chrome 或 chromium 配置文件文件夹中的实际用户文件系统访问文件夹.或者,创建一个本地脚本以将 File System 中的文件夹复制到另一个目录,并将文件夹重命名为已上传文件夹的原始名称.不调整文件夹和文件路径,只调整文件夹名称.

Alternatively, can access folder from actual user filesystem at chrome or chromium profile folder using file manager gui or command line interface. 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. The folder and file paths are not adjusted, only the folder names.

能够保留上传的子文件夹的结构(= 上传1 个文件夹和 3 个子文件夹,每个文件夹包含多个文件)?

is able to preserve the structure of uploaded subfolders (= uploading 1 folder with 3 subfolder, each containing several files)?

在文件管理器中,文件夹不会与上传目录命名相同,但应保留文件夹和文件结构.该文件夹应位于 File System 中的最后一个文件夹,位于 chrome 配置文件文件夹中,在 Origins 文件夹之前.另请参阅 如何使用 JavaScript 写入文件(用户目录)?

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. See also How to Write in file (user directory) using 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, "
copied to directory:", dirEntry)
            })
          })
        }, errorHandler)
      }, errorHandler)
    }
  }
}

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

这篇关于jQuery File Upload Plugin:是否可以保留上传文件夹的结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆