问题
I have a situation, where I need to upload a file to my Dropbox Public Folder, and also once uploaded I need to store the uploaded file's public url ? I am using python, and any help on this would be great.
Thanks.
回答1:
Use this to set up a Python SDK in your program
https://www.dropbox.com/developers/start/setup#python
This will give you all of the file information:
folder_metadata = client.metadata('/')
I beleive you are talking about these short links, just so you know, every small link from the public folder is generated only by special request and has an expiration date.
If you want a permanent link skip to step 2.
STEP 1
This information was taken from: https://www.dropbox.com/developers/reference/api
/shares
DESCRIPTION
Creates and returns a shareable link to files or folders.
Note: Links created by the /shares API call expire after thirty days.
URL STRUCTURE
https://api.dropbox.com/1/shares/<root>/<path>
root
The root relative to which path is specified. Valid values are sandbox and dropbox.
path
The path to the file or folder you want a shareable link to.
VERSIONS
0, 1
METHOD
POST
PARAMETERS
locale Use to specify language settings for user error messages and other language
specific text. See the notes above for more information about supported locales.
RETURNS
A shareable link to the file or folder. The link can be used publicly and directs to a preview page of the file. Also returns the link's expiration date in Dropbox's usual date format.
Sample JSON return value for a file
{
"url": "http://db.tt/APqhX1",
"expires": "Wed, 17 Aug 2011 02:34:33 +0000"
}
If you did step 1 don't do step 2.
STEP 2
/files (GET)
DESCRIPTION
Downloads a file. Note that this call goes to the api-content server.
URL STRUCTURE
https://api-content.dropbox.com/1/files/<root>/<path>
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.
VERSIONS
0, 1
METHOD
GET
PARAMETER
rev The revision of the file to retrieve. This defaults to the most recent revision.
RETURNS
The specified file's contents at the requested revision.
The HTTP response contains the content metadata in JSON format within an x-dropbox-metadata header.
ERRORS
404 The file wasn't found at the specified path, or wasn't found at the specified rev.
NOTES
This method also supports HTTP Range Retrieval Requests to allow retrieving partial file contents.`
DONE
来源:https://stackoverflow.com/questions/9801326/how-to-upload-to-dropbox-public-folder-and-get-public-url