Tải tệp lên từ trang web ASP.NET lên tài khoản dropbox

lập trình


CHÀO,
Tôi muốn tải một số tệp văn bản từ ứng dụng web C# .Net của mình lên tài khoản dropbox. Tôi đã tạo Ứng dụng dropbox nhưng không hiểu rõ cách thực hiện điều đó.
Vui lòng giúp tôi cung cấp các bước để tải tệp từ ứng dụng web C# .Net lên tài khoản dropbox.

Cảm ơn!
Naveen

Những gì tôi đã thử:

Tôi đã cài đặt Dropbox.Api.dll và DropNet.dll từ trình quản lý gói nuget. Nhưng không chắc chắn làm thế nào để tiến xa hơn.

Giải pháp 1

Lấy lib DropBox từ đây: .NET – Nhà phát triển – Dropbox[^]

Nhận khóa API của bạn từ đây: Đăng nhập – Dropbox[^]

Và đây là cách thực hiện: .NET – Nhà phát triển – Dropbox[^]

Giải pháp 2

The solution to this is simple and I would highlight the procedure thus:

1.)Create an app from Dropbox App Console. Choose App Folder (this is a preferable option)  or Full Dropbox for Access Type; enter a name for your app (e.g. myapp). Click "Create App" button. 
Another page is displayed, click on "Generate" button under Generated Access Token.
For the rest of this write-up, the generated code will be called "token".

2.)In your Program.cs (assuming you're using Console App), ensure the following namespaces are referenced

C#
using System;
using System.Threading.Tasks;
using Dropbox.Api;
using System.IO;

Then, modify your your code to

C#
class Program
{
  static void Main(string[] args)
  {
     var task = Task.Run(Upload);
     task.Wait();
  }

  static async Task Upload()
  {
    var dbx = new DropboxClient("token");
    var filePath = @"c:\myFile.txt"; //for example

    if(File.Exists(filePath))
    {
      var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
    
      byte[] content;
      using(var reader = new BinaryReader(fileStream))
      {
         content = reader.ReadBytes((int)fileStream.Length);
      }

      using(var mem = new MemoryStream(content))
      {
         await dbx.Files.UploadAsync("/myFile.txt", WriteMode.Overwrite.Instance, body: 
               mem);
      }
    }
  }
}
3.) Add Newtonsoft.Json package using NuGet Package Manager and you are done.

There is a better approach to uploading bigger-sized files. But I hope this suites your scenario.

Giải pháp 3

CHÀO…!
Tôi cần mã tải lên tệp có degin trong dropbox bằng dotnet
Cảm ơn..

コメント

タイトルとURLをコピーしました