Dropbox API上传时无法上传文件问题

本文关键字:文件 问题 API Dropbox | 更新日期: 2023-09-27 18:12:42

我使用HigLabo.Net.Dropbox上传文件到Dropbox。我创建了一个名为同步的应用程序,我正在尝试上传文件。下面是我的代码

 byte[] bytes = System.IO.File.ReadAllBytes(args[1]);   
 UploadFile(bytes,"sundas.jpg","/Apps/synch/");   

public static void UploadFile(byte[] content, string filename, string target)
    {
        string App_key = "xxxxxxxxxxxxxxx";
        string App_secret = "yyyyyyyyyyyyyy";
        HigLabo.Net.OAuthClient ocl = null;
        HigLabo.Net.AuthorizeInfo ai = null;                    
        ocl = HigLabo.Net.Dropbox.DropboxClient.CreateOAuthClient(App_key, App_secret);                        
        ai = ocl.GetAuthorizeInfo();             
        string RequestToken= ai.RequestToken;
        string RequestTokenSecret= ai.RequestTokenSecret;
        string redirect_url = ai.AuthorizeUrl;
        AccessTokenInfo t = ocl.GetAccessToken(RequestToken, RequestTokenSecret); 
        string Token= t.Token;
        string TokenSecret= t.TokenSecret;
        DropboxClient cl = new DropboxClient(App_key, App_secret, Token, TokenSecret); 
        HigLabo.Net.Dropbox.UploadFileCommand ul = new HigLabo.Net.Dropbox.UploadFileCommand();
        ul.Root = RootFolder.Sandbox;
        Console.WriteLine(ul.Root);
        ul.FolderPath = target;
        ul.FileName = filename;
        ul.LoadFileData(content); 
        Metadata md = cl.UploadFile(ul);
        Console.WriteLine("END");
    }

代码执行正常,但文件无法在Dropbox中上传。

我错过了什么吗?上传路径是否正确?我如何在Dropbox中查看文件是否上传?

是否有一个设置,我错过了,而创建应用程序?我只是在看主页,我期待在根文件夹的文件。我说的对吗?

或者我需要去其他地方看看吗?

Dropbox API上传时无法上传文件问题

谢谢@smarx和@Greg .

下面是完成任务的代码。再次感谢您的支持,希望对大家有所帮助。

string filePath="C:''Tim''sundar.jpg";
RestClient client = new RestClient("https://api-content.dropbox.com/1/");
IRestRequest request = new RestRequest("files_put/auto/{path}", Method.PUT);
FileInfo fileInfo = new FileInfo(filePath);
long fileLength = fileInfo.Length;
request.AddHeader("Authorization", "Bearer FTXXXXXXXXXXXXXXXXXXXisqFXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
request.AddHeader("Content-Length", fileLength.ToString());
request.AddUrlSegment("path", string.Format("Public/{0}", fileInfo.Name));
byte[] data = File.ReadAllBytes(filePath);
var body = new Parameter
{
    Name = "file",
    Value = data,
    Type = ParameterType.RequestBody,
};
request.Parameters.Add(body);
IRestResponse response = client.Execute(request);