简体   繁体   中英

Dropbox v2.0 API Uploading File

So i need to upload a file into my dropbox account using c#

I'm currently using Dropbox API v2.0 which is relatively new.

I'm working with winforms c# and I was given this example code from Dropbox themselves here : https://www.dropbox.com/developers/documentation/dotnet#tutorial

I need some help tho, I don't quite understand How I'd call Upload in a winforms.

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        var task = Task.Run((Func<Task>)this.Upload);
        task.Wait();
    }

    async Task Upload()
    {
        DropboxClient dbx = new DropboxClient("FF5tO7fs20AAAAAAAAALcjFNxDeEpWSneNOPl6ya9276gFB7s7pUJKVI2vAxFcSs");
        var file = "159386425737-IPs.txt";
        var mem = new MemoryStream(Encoding.UTF8.GetBytes("TESTING" + IPCount.ToString()));
        try
        {
            var updated = await dbx.Files.UploadAsync(file, WriteMode.Overwrite.Instance, body: mem);
        }
        catch (Exception e)
        {
            MessageBox.Show(e.ToString());
        }
    }

Error I'm getting is on this line

var updated = await.....

and this is the runtime error it is throwing

System.ArgumentsOutOfRangeException: Specified argument was out of range of valid values.
Parameter name: Path

and this error

Dropbox.Api.BadInputException : Error in call to API function "files/upload" : HTTP header "Dropbox-Api-Arg": path: "folder//file"" did not match parretn '/.*'

Since the function is declared as async and returns the task that represents the asynchronous method call, you just need to make sure that you wait for the Task to finish before letting the form close. Try this...

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    var task = Upload("APPKEY", "FILELOCATION","TEXT.TXT","CONTENT TEXT HERE");
    task.Wait();

}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM