I want to download file from my drop-box using Dropbox API, the API documentation is quite complicated and messy can any one suggest me a simpler approach to download file as my path is:
/uploads/2017 0730 Invoice Explanation (1).doc
i have find a way but for this approach I have to create a shareable link for the file, I want to download here is the approach:
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
}
Using above path can I download a file any help will be appreciated.
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);
}
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.