File upload failed while uploading into dropbox in

2019-03-06 17:47发布

问题:

I'm failing to upload files into dropbox in iOS in CoreApI

I'm getting this message

[WARNING] DropboxSDK: error making request to /1/files_put/sandboxsandbox/helloworld.txt - (400) Expected 'root' to be 'dropbox', 'sandbox', or 'auto', got u'sandboxsandbox' 2013-12-04 18:23:57.348 DropBoxCore[4914:907] File upload failed with error - Error Domain=dropbox.com Code=400 "The operation couldn’t be completed. (dropbox.com error 400.)" UserInfo=0x22b1d7f0 {sourcePath=/var/mobile/Applications/28B2865A-58BC-4DC8-8E61-7F40307DDC56/DropBoxCore.app/helloworld.txt, destinationPath=sandbox/helloworld.txt, error=Expected 'root' to be 'dropbox', 'sandbox', or 'auto', got u'sandboxsandbox'}

Could someone please help me, I have searched for this, but couldn't find any solutions for this problem.

回答1:

It would help if you shared your code, but my guess is that your passing in a path like sandbox/helloworld.txt and should instead pass /helloworld.txt. If that's not it, please do share your code.



回答2:

From the Dropbox docs for file_put:

URL Structure

https://api-content.dropbox.com/1/files_put/<root>/<path>?param=val

root The root relative to which path is specified. Valid values are sandbox and dropbox.

path The path to the file you want to retrieve.

A key bit of information in your error message is the path portion of the URI made in the request. Relevant line from your error message:

error making request to /1/files_put/sandboxsandbox/helloworld.txt

Compared to the URL structure from the docs, for <root> you've used sandboxsandbox, but the docs say only sandbox and dropbox are valid values.

The error in the JSON response body has a similar clue:

error=Expected 'root' to be 'dropbox', 'sandbox', or 'auto', got u'sandboxsandbox'

Referring to the API docs is unnecessary as the error message spells out that sandboxsandbox isn't among the list of valid values for root.

Though slightly less obvious, this bit in the JSON when compared to the URL structure and the documentation gives a hint:

destinationPath=sandbox/helloworld.txt

After a small leap that destinationPath corresponds to path in the API docs and reading that root is "the root relative to which path is specified" you can surmise that the path shouldn't contain the root. Whether it should be /helloworld.txt or helloworld.txt can be deduced by seeing that the URL structure already accounts for a / between <root> and <path>. Compare these expansions using /helloworld.txt and helloworld.txt respectively:

/1/files_put/<root>/<path>
/1/files_put/sandbox/<path>
/1/files_put/sandbox//helloworld.txt

/1/files_put/<root>/<path>
/1/files_put/sandbox/<path>
/1/files_put/sandbox/helloworld.txt

It should be clear which value of path is correct.



标签: dropbox