2014-06-21 70 views
0

請有人可以幫助我告訴我如何修改此腳本(挑選)以獲取大小和mimetype文件的下載和共享鏈接使用Onedrive API,而無需下載文件(如在此函數):獲取下載和共享鏈接使用Onedrive(skydire)API而無需下載

WL.init({ client_id: clientId, redirect_uri: redirectUri }); 

WL.login({ "scope": "wl.skydrive wl.signin" }).then(
    function(response) { 
     openFromSkyDrive(); 
    }, 
    function(response) { 
     log("Failed to authenticate."); 
    } 
); 

function openFromSkyDrive() { 
    WL.fileDialog({ 
     mode: 'open', 
     select: 'single' 
    }).then(
     function(response) { 
      log("The following file is being downloaded:"); 
      log(""); 

      var files = response.data.files; 
      for (var i = 0; i < files.length; i++) { 
       var file = files[i]; 
       log(file.name); 
       WL.download({ "path": file.id + "/content" }); 
      } 
     }, 
     function(errorResponse) { 
      log("WL.fileDialog errorResponse = " + JSON.stringify(errorResponse)); 
     } 
    ); 
} 

function log(message) { 
    var child = document.createTextNode(message); 
    var parent = document.getElementById('JsOutputDiv') || document.body; 
    parent.appendChild(child); 
    parent.appendChild(document.createElement("br")); 
} 

演示鏈接:http://isdk.dev.live.com/dev/isdk/ISDK.aspx?category=scenarioGroup_skyDrive&index=0

謝謝您的幫助。通過這個版本的openFromSkyDrive的

ID,描述,名稱,類型,鏈接,upload_location,源,照片

回答

1

我可以對該被從選擇器返回的文件變量以下屬性()方法:

function openFromSkyDrive() { 
WL.fileDialog({ 
    mode: 'open', 
    select: 'single' 
}).then(
    function(response) { 
     log("The following file is being downloaded:"); 
     log(""); 

     var files = response.data.files; 
     for (var i = 0; i < files.length; i++) { 
      var file = files[i]; 
      log(file.name); 

      /* show all the the properties of 'file' variable */ 
      for(var p in file){ 
       log(p); 
      } 

      /* get the type, which really isn't a full mimetype */ 
      log(file.type); 

      /* get the share link */ 
      log(file.link); 

      /* do not download the file */ 
      // WL.download({ "path": file.id + "/content" }); 
     } 
    }, 
    function(errorResponse) { 
     log("WL.fileDialog errorResponse = " + JSON.stringify(errorResponse)); 
    } 
); 
}