2017-08-28 23 views
0

我想使用Dropbox的API我的Dropbox下載文件,API文檔是相當複雜和混亂的任何一個可以建議我一個簡單的方法來下載文件爲我的路徑是:下載來自收件箱文件中的JavaScript

/uploads/2017 0730 Invoice Explanation (1).doc 

我有找到一種方法,但是這種方法我要創建一個共享鏈接的文件,我想在這裏下載的辦法:

function downloadFile() { 
     var dbx = new Dropbox({accessToken: 'XXXXXXXXXAAAXXXXXXXXXXXXXXXX'}); 
     dbx.sharingGetSharedLinkFile({url: 'https://www.dropbox.com/s/9f4grw8cvqlxwqg/067360_POWERDALE-DEE%20%281%29.KMZ?dl=0'})// here i mentioned the shareable link rather then I want to specify path 
      .then(function (data) { 
       var downloadUrl = URL.createObjectURL(data.fileBlob); 
       var downloadButton = document.createElement('a'); 
       downloadButton.setAttribute('href', downloadUrl); 
       downloadButton.setAttribute('download', data.name); 
       downloadButton.setAttribute('class', 'button'); 
       downloadButton.innerText = 'Download: ' + data.name; 
       document.getElementById('results').appendChild(downloadButton); 
      }) 
      .catch(function (error) { 
       console.error(error); 
      }); 
     return 

    } 

使用上述路徑,我可以下載一個文件的任何幫助將不勝感激。

+0

請參閱本https://stackoverflow.com/questions/39959444/issues-downloading-files-using-dropbox-javascript-sdk –

+0

@HarshPatel使用這個我需要設置節點,但我的要求僅限於JS –

+0

[官方Dropbox API v2 JavaScript SDK](https://github.com/dropbox/dropbox-sdk-js)同時支持節點和瀏覽器JavaScript。這裏有一個關於使用'filesDownload'的線程:https://www.dropboxforum.com/t5/API-support/JS-SDK-filesDownload-How-do-I-get-the-file-content/mp/238336# M13198 – Greg

回答

0
Please check the below answer 

    public ActionResult Index() 
     { 
      SignInToDropBox(); 
      return View(); 
     } 
     public void SignInToDropBox() 
     { 
      string[] stringArray = new string[6]; 
      Program p = new Program(); 

      p.Main(stringArray); 

     } 
     class Program 
     { 
      public void Main(string[] args) 
      { 
       //var task = Task.Run((Func<Task>)Program.Run); 
       //task.Wait(); 
       var task3 = Task.Run((Func<Task>)Program.Download); 
       task3.Wait(); 
      } 

static async Task Download() 
      { 

       using (var dbx = new DropboxClient("yHFdFxdeNzAAAAAAAAAAKSONCez08ZrwRJ90Fdf5uvFk-aDkgih661r_KVoUko9Q")) //"Your Access Token 
       { 
        string fileName = "D://downloa.pdf"; 
        // string file = "ltest.pdf"; 
        using (var response = await dbx.Files.DownloadAsync("/Akhil/get.pdf",null)) 
        { 

         byte[] toBytes = Encoding.ASCII.GetBytes(await response.GetContentAsStringAsync()); 


         try 
         { 
          using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write)) 
          { 
           fs.Write(toBytes, 0, toBytes.Length); 

          } 
         } 
         catch (Exception ex) 
         { 
          Console.WriteLine("Exception caught in process: {0}", ex); 

         } 
        } 
       } 
      } 
     } 
+0

在上面的代碼中,我使用了asp.net MVc開發 –

+0

/Akhil/get.pdf是您需要從DropBox下載的文件,我們正在將它寫入downloa.pdf。 –

+0

更多參考檢查:https://www.dropbox.com/developers/documentation/dotnet#tutorial –