File uploading Dropbox v2.0 API

前端 未结 2 891
孤街浪徒
孤街浪徒 2021-01-06 06:12

I\'m using the new Dropbox SDK v2 for .NET.

I\'m trying to upload a document to a Dropbox account.

public async Task UploadDoc()
    {
        using          


        
2条回答
  •  抹茶落季
    2021-01-06 06:40

    You can use the following method if you just want to upload a file with a given path:

    private async Task Upload(DropboxClient dbx, string folder, string file, string fileToUpload)
        {
            using (var mem = new MemoryStream(File.ReadAllBytes(fileToUpload)))
            {
                var updated = await dbx.Files.UploadAsync(
                    folder + "/" + file,
                    WriteMode.Overwrite.Instance,
                    body: mem);
                Console.WriteLine("Saved {0}/{1} rev {2}", folder, file, updated.Rev);
            }
        }
    

    Parameter example:

    folder = "/YourDropboxFolderName";
    file = "fileName.pdf";
    fileToUpload = @"C:\Users\YourUserName\fileName.pdf";
    

提交回复
热议问题