簡體   English   中英

jQuery 文件上傳插件:是否可以保留上傳文件夾的結構?

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

我正在嘗試這個插件( https://github.com/blueimp/jQuery-File-Upload )並且在文件夾上傳中很有趣。

我想知道該插件是否能夠保留上傳的子文件夾的結構(= 上傳 1 個文件夾和 3 個子文件夾,每個文件夾包含多個文件)?

這應在可能webkit使用拖放和拖放瀏覽器.dataTransfer對象在drop事件; .webkitGetAsEntry() ; webkitRequestFileSystem getDirectory()創建與上傳文件夾同名的目錄, .createReader()DirectoryEntryreadEntries()迭代目錄中的條目,為每個FileEntry調用.copyTo()目標正在創建的目錄具有上傳的目錄名稱。

現在應該可以使用webkitRequestFileSystem()訪問該文件夾,然后使用目錄名稱作為第一個參數和空選項對象{}作為第二個參數調用.getDirectory()

或者,可以使用文件管理器 gui 或命令行界面從 chrome 或chromium 配置文件文件夾中的實際用戶文件系統訪問文件夾。 或者,創建一個本地腳本將File System中的File System夾復制到另一個目錄,並將文件夾重命名為已上傳文件夾的原始名稱。 不調整文件夾和文件路徑,只調整文件夾名稱。

是否能夠保留上傳的子文件夾的結構(= 上傳 1 個文件夾和 3 個子文件夾,每個文件夾包含多個文件)?

在文件管理器中,文件夾的名稱不會與上傳的目錄相同,但應保留文件夾和文件結構。 該文件夾應位於File System中 chrome 配置文件文件夾中的最后一個文件夾,在Origins文件夾之前。 另請參閱如何使用 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM