Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropbox API 2 - UploadAsync returns invalid path error

Tags:

c#

.net

dropbox

I'm new to trying to integrate with a third party API and it's turning out to be tedious. Let me first explain my goal: Create a file (a .txt file), and upload it to a single Dropbox account for a user to retrieve later. Before it gets to the upload process, the file is all set to go as a memorystream. I then try to use this simple code (for testing purposes) to upload to my account, which I have the key for. Here's a general snippet of usage:

public async Task<string> ReturnNewUploader(FileDetailObject fdo) {
var dbx = new DropboxClient("MY KEY");
fdo.DropboxClient = dbx;
var action = await fileUploader.UploadFileAsync(fdo);
...}

public async Task<string> UploadFileAsync(FileDetailObject fdo) {
var dropbox = await fdo.DropboxClient.Users.GetCurrentAccountAsync();
var req = await fdo.DropboxClient.Files.UploadAsync("TestFolder/test.txt"   WriteMode.Overwrite.Instance, body: fdo.MemStream); 

The above is where the exception is thrown:

Value should match pattern '\A(?:(/(.|[\r\n]))|(ns:[0-9]+(/.)?)|(id:.*))\z'
Parameter name: path
ParamName: path

StackTrace: at Dropbox.Api.Files.CommitInfo..ctor(String path, WriteMode mode, Boolean autorename, Nullable`1 clientModified, Boolean mute)
at Dropbox.Api.Files.Routes.FilesUserRoutes.UploadAsync(String path, WriteMode mode, Boolean autorename, Nullable`1 clientModified, Boolean mute, Stream body)
at appname.BusinessLogic.FTPer.d__3.MoveNext() in C:.........\appname\appname.BusinessLogic\FTPer.cs:line 78

I don't understand what's wrong with the path - it seems to match what they're expecting. The directory exists on the account. I've tried it without using a folder either and just passing a filename and I get the same error.

Thoughts? Also, if this can be implemented more cleanly I'm absolutely open to suggestions. Just know that this really cannot use a login prompt and has to write out to a single Dropbox account which we control.

like image 889
lrossignol Avatar asked Mar 16 '26 15:03

lrossignol


1 Answers

Non-root file paths should start with '/', so instead of:

"TestFolder/test.txt"

you should have something like:

"/TestFolder/test.txt"

like image 105
Greg Avatar answered Mar 18 '26 05:03

Greg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!