2017-05-24 153 views

回答

0

使用curl命令我們使用:

  • curl -X MKCOL <folder_URL>創建文件夾
  • curl -X PUT <folder_URL>/<file_name> --data-binary @<file_location_in_pc>要上傳的文件。

這是代碼的示例:

/** 
    * Upload a file to an user folder 
    * @param userId 
    * @param fileName 
    * @param fileLocation 
    * @param callback 
    */ 
    function fnUploadDocument(userId, fileName, fileLocation, callback) { 
    var json = { 
     done: false 
    } 
    var command = 'curl -X PUT "' 
    command += srv.ownclouddirUtil.getUrlUser() 
    command += srv.h3apifolder + userId + '/' 
    command += fileName + '"' 
    command += ' --data-binary @"' + fileLocation + '"' 
    console.log('Command--: ', command) 
    srv.fileSystemService.runScript(command, function (stdout, error, stderr) { 
     if (error === null) { 
     json.done = true 
     callback(json) 
     } else { 
     json.error = error 
     json.stderr = stderr 
     callback(json) 
     } 
    }) 
    }