Dropbox Bean
Properties Methods Events Configuration Settings Errors
The Dropbox component provide an easy way to upload, download, and manage files and folders with Dropbox.
Syntax
InCloudStorage.Dropbox
Remarks
The Dropbox component provides a simple interface to working with Dropbox. Capabilities include uploading and downloading files, strong encryption support, creating folders, moving and copying resource, and more.
To begin, first create an account and register your application with Dropbox. Consult the Dropbox documentation for instructions on this process.
Authentication
Authentication is performed via OAuth 2.0. Use the OAuth component included in the toolkit, or any other OAuth
implementation to perform authentication and retrieve an authorization string. Once you've obtained an
authorization string like:
Bearer ya29.AHES6ZSZEJzATdZYjeihDn5W-VrXSsxEZu5p0pclxGdKKQAssign this value to the Authorization property before attempting any operations. Consult the Dropbox documentation for this particular service for more information about supported scope values and more details on OAuth authentication.
Listing Resources
ListResources lists resources within the account at the specified path.
Before calling this method set ResourcePath to the full path to the folder to list. If ResourcePath is unspecified the root folder contents will be listed.
After calling this method set ResourceIndex to a value from 0 to ResourceCount - 1. Setting ResourceIndex populates other Resource properties to provide information about the resource.
After calling this method the following resource properties are populated:
- ResourceCount
- ResourceId
- ResourceMarker
- ResourceModifiedDate
- ResourceName
- ResourcePath
- ResourceRevision
- ResourceType
If the ResourceType is 1 (rtFolder) only the following properties are applicable:
If the results are paged, the ResourceMarker property will be populated. Call this method again to retrieve the next page of results. When the last page of results is returned ResourceMarker will be empty.
By default only resources of the specified ResourcePath are returned. To list files included within subfolders
set RecurseSubfolders to True.
dropbox.ResourcePath = "/New Folder"; dropbox.ListResources(); for (int i = 0; i < dropbox.ResourceCount; i++) { dropbox.ResourceIndex = i; Console.WriteLine(dropbox.ResourceName + ": " + dropbox.ResourceSize); }
Downloading Files
The DownloadFile method downloads a specific file.
Set ResourcePath to the absolute path of the file to download before calling this method. The file will be downloaded to the stream specified (if any) by SetDownloadStream. If a stream is not specified and LocalFile is set the file will be saved to the specified location. If a stream is not specified and LocalFile is not set the file data will be held by ResourceData.
To decrypt an encrypted file set EncryptionAlgorithm and EncryptionPassword before calling this method.
dropbox.ResourcePath = "/My Folder/photos.zip" dropbox.LocalFile = "../MyFile.zip"; dropbox.DownloadFile();
Resuming Downloads
The component also supports resuming failed downloads by using the StartByte property. If the download was interrupted, set StartByte to the appropriate offset before calling this method to resume the download.
dropbox.ResourcePath = myRemoteFile; dropbox.LocalFile = downloadFile; dropbox.DownloadFile(); //The transfer is interrupted and DownloadFile() above fails. Later, resume the download: //Get the size of the partially download file dropbox.StartByte = new FileInfo(downloadFile).Length; dropbox.ResourcePath = myRemoteFile; dropbox.LocalFile = downloadFile; dropbox.DownloadFile();
Resuming Encrypted File Downloads
Resuming encrypted file downloads is only supported when LocalFile was set in the initial download attempt. When beginning an encrypted download if LocalFile is set the component will create a temporary file in TempPath to hold the encrypted data until it is complete.
If the download is interrupted DownloadTempFile will be populated with the temporary file holding the partial data.
When resuming, DownloadTempFile must be populated along with StartByte to allow the remainder of the encrypted data
to be downloaded. Once the encrypted data is downloaded it will be decrypted and written to LocalFile.
dropbox.ResourcePath = myRemoteFile; dropbox.LocalFile = downloadFile; dropbox.EncryptionPassword = "password"; dropbox.DownloadFile(); //The transfer is interrupted and DownloadFile() above fails. Later, resume the download: //Get the size of the partially download temp file dropbox.StartByte = new FileInfo(dropbox.Config("DownloadTempFile")).Length; dropbox.ResourcePath = myRemoteFile; dropbox.LocalFile = downloadFile; dropbox.EncryptionPassword = "password"; dropbox.DownloadFile();
Uploading Files
LocalFile specifies the file to upload. The data to upload may also be set in ResourceData or set by SetUploadStream.
The FileName parameter of UploadFile specifies the name of the file to be written.
A file can be uploaded to a specific folder by specifying the absolute path in the FileName parameter,
or by setting ResourcePath to the folder. Absolute paths begin with a "/" character and must include the full
path beginning at the root. For instance:
//Upload to the root folder dropbox.ResourcePath = ""; string path = dropbox.UploadFile("test.txt"); //path is "/test.txt" //Upload to a folder (relative path) dropbox.CreateFolder("/uploadtest"); path = dropbox.UploadFile("test.txt"); //path is "/uploadtest/test.txt" //Upload to a folder (absolute path) path = dropbox.UploadFile("/uploadtest/test.txt"); //path is "/uploadtest/test.txt"
To encrypt a file before uploading set EncryptionAlgorithm and EncryptionPassword.
When the upload is complete the component will fire the UploadComplete event and UploadFile returns the absolute path to the uploaded file.
Upload Notes
Dropbox offers two ways to upload a file. For smaller files a simple upload option is provided to upload data in one request. This is the default option. For larger files uploads can be fragmented into multiple pieces, allowing resuming of uploads that may be interrupted.
Simple
By default the component uses the simple upload mechanism. Simple uploads are the only supported option when SetUploadStream is used.
dropbox.LocalFile = "../MyFile.zip"; dropbox.UploadFile("/folder/MyFile.zip");
The following properties are applicable when calling UploadFile and UseResumableUpload if False (default - simple upload):
Resumable
To enable resumable uploads set UseResumableUpload to True. This is recommended for large files. The component will automatically fragment the specified file into smaller pieces and upload each individually. FragmentSize may be set to specify the size of the fragment if desired. The default fragment size is 10 MB.
When UseResumableUpload is set to True and UploadFile is called a resumable upload session is started by the component. UploadSessionId is populated with the Id of the session. This value may be needed for additional operations if the upload does not complete normally. Additionally StartByte is updated as necessary by the component to indicate the current offset in the file.
If the upload is interrupted for any reason the upload may be resumed. To resume an upload verify that UploadSessionId and StartByte are populated. If the same instance of the component is used these should already be populated and no special action is needed. Call UploadFile again to resume the upload at the specified StartByte offset.
The FragmentComplete event fires after each fragment is uploaded to indicate overall progress.
dropbox.LocalFile = "../MyFile.zip"; dropbox.UploadFile("MyFile.zip"); //The transfer is interrupted and UploadFile() above fails. Later, resume the download. //Using the same instance StartByte and UploadSessionId are already populated //from the previous upload attempt dropbox.UploadFile("MyFile.zip");
The following properties are applicable when calling UploadFile and UseResumableUpload if True:
Additional Functionality
The Dropbox component offers advanced functionality beyond simple uploads and downloads. For instance:
- Encrypt and decrypt files using EncryptionAlgorithm and EncryptionPassword.
- Use CopyResource, MoveResource, and DeleteResource to manage files and folders.
- ShareResource creates shareable links to content.
- ListChanges lists all changes in a folder from a given point to facilitate syncing local and remote copies.
- Search can be used to search for matching content.
- Revisions are supported through ListRevisions and RestoreResource.
- GetUsageInfo and GetAccountInfo provide usage and account information.
- GetPreview and GetThumbnail retrieve preview information for files.
- And more!
Property List
The following is the full list of the properties of the bean with short descriptions. Click on the links for further details.
Account | This property defines information about the account. |
Authorization | OAuth 2.0 Authorization Token. |
ChangeMarker | A marker identifying the last change in a folder. |
EncryptionAlgorithm | The encryption algorithm. |
EncryptionPassword | The encryption password. |
Firewall | A set of properties related to firewall access. |
LocalFile | The location of the local file. |
LocalHost | The name of the local host or user-assigned IP interface through which connections are initiated or accepted. |
Overwrite | Whether to overwrite the local or remote file. |
Proxy | A set of properties related to proxy access. |
ResourceCount | The number of files and folders. |
ResourceData | Holds the file data after downloading or sets the file data before uploading or updating. |
ResourceId | A unique identifier for the resource. |
ResourceIndex | Selects the file or folder. |
ResourceMarker | A marker when list results are paged. |
ResourceModifiedDate | The last time the resource was modified on Dropbox. |
ResourceName | The name of the resource. |
ResourcePath | The path of the current resource. |
ResourceRevision | The current revision of the file. |
ResourceSize | The size of the resource in bytes. |
ResourceType | Indicates whether the current entry is a folder or a file. |
SearchMarker | A marker when searches are paged. |
SearchMode | The level at which to search. |
SharedResources | A collection of information about the shared resource(s). |
SSLAcceptServerCert | Instructs the component to unconditionally accept the server certificate that matches the supplied certificate. |
SSLCert | The certificate to be used during SSL negotiation. |
SSLServerCert | The server certificate for the last established connection. |
StartByte | The byte offset from which to start the upload or download. |
ThumbnailFormat | The thumbnail format. |
ThumbnailSize | The size of the thumbnail in pixels. |
Timeout | A timeout for the component. |
TotalSpace | The total allowed space in bytes. |
UploadSessionId | The Id of the resumable upload session. |
UsedSpace | The amount of space used in bytes. |
UseResumableUpload | Whether to use resumable uploads. |
Method List
The following is the full list of the methods of the bean with short descriptions. Click on the links for further details.
config | Sets or retrieves a configuration setting . |
copyResource | Copies the file or folder specified by ResourcePath to a new location. |
createFolder | Creates the folder at the specified path. |
deleteResource | Deletes the specified resource. |
downloadFile | Downloads the specified file. |
getAccountInfo | Gets information about the account. |
getPreview | This method download a preview of a resource. |
getResourceInfo | Gets information about the specified resource. |
getThumbnail | Gets a thumbnail image. |
getUsageInfo | Gets the total space allowed and used. |
interrupt | Interrupt the current method. |
listChanges | List recent changes to a folder. |
listResources | Lists the resources in the current folder. |
listRevisions | Lists file revisions. |
listSharedResources | This method lists information about the shared resources. |
moveResource | Moves the file or folder specified by ResourcePath to a new location. |
restoreResource | Restores a file to a previous revision. |
search | Searches for files and folders matching the query. |
setDownloadStream | Sets the stream to which the downloaded file will be written. |
setUploadStream | Sets the stream from which data is read when uploading. |
shareResource | Shares a resource. |
unshareResource | This method un-shares the resource. |
uploadFile | Uploads a file. |
waitForChanges | This method waits for changes to a folder for a specified period of time. |
Event List
The following is the full list of the events fired by the bean with short descriptions. Click on the links for further details.
EndTransfer | Fired when a document finishes transferring. |
Error | Information about errors during data delivery. |
FragmentComplete | This event fires after each fragment of a resumable upload is completed. |
ResourceList | Fired for each resource listed. |
SearchResult | Fired for each search result. |
SharedResourceList | This event fires when ListSharedResources is called. |
SSLServerAuthentication | Fired after the server presents its certificate to the client. |
SSLStatus | Shows the progress of the secure connection. |
StartTransfer | Fired when a document starts transferring (after the headers). |
Transfer | Fired while a document transfers (delivers document). |
UploadComplete | Fires after an upload completes. |
Configuration Settings
The following is a list of configuration settings for the bean with short descriptions. Click on the links for further details.
DownloadTempFile | The temporary file used when downloading encrypted data. |
FragmentSize | The fragment size. |
MaxResults | The maximum number of search results per page. |
PermanentlyDelete | Whether to permanently delete a resource. |
RecurseSubfolders | Whether to recurse subfolders when listing resources. |
RenameIfExists | Whether to rename the uploaded file if it exists. |
ResourceClientDate | The client modified date. |
ShortURL | Whether to use a shortened URL for the shared resource. |
TempPath | The path to the directory where temporary files are created. |
EncryptionIV | The initialization vector to be used for encryption/decryption. |
EncryptionKey | The key to use during encryption/decryption. |
XPath | Provides a way to point to a specific element in the returned XML response. |
XElement | The name of the current element. |
XParent | The parent of the current element. |
XSubTree | A snapshot of the current element in the document. |
XText | The text of the current element. |
XChildCount | The number of child elements of the current element. |
XChildName[x] | The name of the child element. |
XChildXText[x] | The inner text of the child element. |
AcceptEncoding | Used to tell the server which types of content encodings the client supports. |
AllowHTTPCompression | This property enables HTTP compression for receiving data. |
AllowIdenticalRedirectURL | Allow redirects to the same URL. |
Append | Whether to append data to LocalFile. |
Authorization | The Authorization string to be sent to the server. |
BytesTransferred | Contains the number of bytes transferred in the response data. |
EncodeURL | If set to true the URL will be encoded by the component. |
FollowRedirects | Determines what happens when the server issues a redirect. |
GetOn302Redirect | If set to true the component will perform a GET on the new location. |
HTTPVersion | The version of HTTP used by the component. |
IfModifiedSince | A date determining the maximum age of the desired document. |
KeepAlive | Determines whether the HTTP connection is closed after completion of the request. |
MaxRedirectAttempts | Limits the number of redirects that are followed in a request. |
OtherHeaders | Other headers as determined by the user (optional). |
ProxyAuthorization | The authorization string to be sent to the proxy server. |
ProxyAuthScheme | The authorization scheme to be used for the proxy. |
ProxyPassword | A password if authentication is to be used for the proxy. |
ProxyPort | Port for the proxy server (default 80). |
ProxyServer | Name or IP address of a proxy server (optional). |
ProxyUser | A user name if authentication is to be used for the proxy. |
TransferredDataLimit | The maximum number of incoming bytes to be stored by the component. |
TransferredHeaders | The full set of headers as received from the server. |
UseChunkedEncoding | Enables or Disables HTTP chunked encoding for transfers. |
ChunkSize | Specifies the chunk size in bytes when using chunked encoding. |
UserAgent | Information about the user agent (browser). |
KerberosSPN | The Service Principal Name for the Kerberos Domain Controller. |
ConnectionTimeout | Sets a separate timeout value for establishing a connection. |
FirewallAutoDetect | Tells the component whether or not to automatically detect and use firewall system settings, if available. |
FirewallHost | Name or IP address of firewall (optional). |
FirewallPassword | Password to be used if authentication is to be used when connecting through the firewall. |
FirewallPort | The TCP port for the FirewallHost;. |
FirewallType | Determines the type of firewall to connect through. |
FirewallUser | A user name if authentication is to be used connecting through a firewall. |
KeepAliveTime | The inactivity time in milliseconds before a TCP keep-alive packet is sent. |
KeepAliveInterval | The retry interval, in milliseconds, to be used when a TCP keep-alive packet is sent and no response is received. |
Linger | When set to True, connections are terminated gracefully. |
LingerTime | Time in seconds to have the connection linger. |
LocalHost | The name of the local host through which connections are initiated or accepted. |
LocalPort | The TCP port in the local host where the component binds. |
MaxLineLength | The maximum amount of data to accumulate when no EOL is found. |
MaxTransferRate | The transfer rate limit in bytes per second. |
RecordLength | The length of received data records. |
TCPKeepAlive | Determines whether or not the keep alive socket option is enabled. |
UseIPv6 | Whether to use IPv6. |
TcpNoDelay | Whether or not to delay when sending packets. |
ReuseSSLSession | Determines if the SSL session is reused. |
SSLCipherStrength | The minimum cipher strength used for bulk encryption. |
SSLEnabledProtocols | Used to enable/disable the supported security protocols. |
SSLProvider | The name of the security provider to use. |
SSLSecurityFlags | Flags that control certificate verification. |
OpenSSLCADir | The path to a directory containing CA certificates. |
OpenSSLCAFile | Name of the file containing the list of CA's trusted by your application. |
OpenSSLCipherList | A string that controls the ciphers to be used by SSL. |
OpenSSLPrngSeedData | The data to seed the pseudo random number generator (PRNG). |
AbsoluteTimeout | Determines whether timeouts are inactivity timeouts or absolute timeouts. |
FirewallData | Used to send extra data to the firewall. |
InBufferSize | The size in bytes of the incoming queue of the socket. |
OutBufferSize | The size in bytes of the outgoing queue of the socket. |
CodePage | The system code page used for Unicode to Multibyte translations. |