Dropbox Component
Properties Methods Events Configuration Settings Errors
The Dropbox component makes it easy to upload, download, and manage files and folders within Dropbox.
Syntax
nsoftware.IPWorksCloud.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 resources, and more.
Authentication
This component supports authentication via OAuth 2.0. First, perform OAuth authentication using the OAuth component or a separate process. Once complete you should have an authorization string which looks like:
Bearer ya29.AHES6ZSZEJzATdZYjeihDn5W-VrXSsxEZu5p0pclxGdKKQAssign this value to the Authorization property before attempting any operations. Consult the documentation for the service for more information about supported scope values and more details on OAuth authentication.
Addressing Resources
Dropbox typically allows resources to be addressed in multiple ways:
- Using a path (e.g., /path/to/resource.txt).
- Using a resource Id (e.g, id:xxxxx).
- Using an Id-based relative path (e.g., id:xxxxx/relative/path/test.txt, where the Id is that of a folder resource).
- For certain methods, using a revision Id (e.g., rev:xxxxx).
Listing Resources
ListResources lists resources within the specified folder. Calling this method will fire the ResourceList event once for each resource, and will also populate the Resources collection.
If there are still more resources available to list when this method returns, the ResourceMarker property will be populated. Continue to call this method until ResourceMarker is empty to accumulate all pages of results in the Resources collection.
// ResourceList event handler. dropbox.OnResourceList += (s, e) => { Console.WriteLine(e.Name); }; do { dropbox.ListResources("/work_files/serious_business/cats"); for (int i = 0; i < dropbox.Resources.Count; i++) { // Process resources here. } } while (!string.IsNullOrEmpty(dropbox.ResourceMarker));
Downloading Files
The DownloadFile method downloads file resources.
If a stream has been specified using SetDownloadStream, the file data will be sent through it. If a stream is not specified, and LocalFile is set, the file will be saved to the specified location; otherwise, the file data will be held by ResourceData.
To download and decrypt an encrypted file, set EncryptionAlgorithm and EncryptionPassword before calling this method.
Download Notes
In the simplest use-case, downloading a file looks like this:
dropbox.LocalFile = "../MyFile.zip"; dropbox.DownloadFile(dropbox.Resources[0].Id);
Resuming Downloads
The component also supports resuming failed downloads by using the StartByte property. If a download is interrupted, set StartByte to the appropriate offset before calling this method to resume the download.
string downloadFile = "../MyFile.zip"; dropbox.LocalFile = downloadFile; dropbox.DownloadFile(dropbox.Resources[0].Id); //The transfer is interrupted and DownloadFile() above fails. Later, resume the download: //Get the size of the partially downloaded file dropbox.StartByte = new FileInfo(downloadFile).Length; dropbox.DownloadFile(dropbox.Resources[0].Id);
Resuming Encrypted File Downloads
Resuming encrypted file downloads is only supported when LocalFile was set in the initial download attempt.
If LocalFile is set when beginning an encrypted download, the component creates a temporary file in TempPath to hold the encrypted data until the download is complete. If the download is interrupted, DownloadTempFile will be populated with the path of the temporary file that holds the partial data.
To resume, 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.LocalFile = "../MyFile.zip"; dropbox.EncryptionPassword = "password"; dropbox.DownloadFile(dropbox.Resources[0].Id); //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.DownloadFile(dropbox.Resources[0].Id);
Uploading Files
The UploadFile method uploads new file resources.
If SetUploadStream has been used to set an upload stream, it will take priority as the file data source. If LocalFile is set the file will be uploaded from the specified path. If LocalFile is not set the data in ResourceData will be used.
To encrypt the file before uploading it, set EncryptionAlgorithm and EncryptionPassword.
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.
dropbox.LocalFile = "../MyFile.zip"; dropbox.UploadFile("/MyFile.zip");
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 a resumable upload session Id identifying the session (this value may be needed for additional operations if the upload does not complete normally).
During a resumable upload, the FragmentComplete event fires after each fragment is uploaded to indicate overall progress. The component also updates StartByte as necessary to indicate the current offset in the file.
If the upload is interrupted for any reason, resuming it is easy. First, verify that UploadSessionId and StartByte are populated (if the same instance of the component is used, they should already be populated, and no special action should be needed). If uploading from a stream, be sure to reset its position to where it was the first time the upload was started (typically the beginning). Then call UploadFile again to resume the upload at the specified StartByte offset.
Note that if the upload is not resumed after some time the upload session will expire.
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 ResumeURL are already populated from the previous //upload attempt. dropbox.UploadFile("MyFile.zip");
MemoryStream uploadStream = new MemoryStream(File.ReadAllBytes("../MyFile.zip")); dropbox.SetUploadStream(uploadStream); dropbox.UploadFile("MyFile.zip"); //The transfer is interrupted and UploadFile() above fails. Later, resume the download. //Using the same instance StartByte and ResumeURL are already populated from the previous //upload attempt. //You MUST reset the stream's position to where it was when you first started the upload! uploadStream.Position = 0; dropbox.UploadFile("MyFile.zip");
Additional Functionality
The Dropbox component offers advanced functionality beyond simple uploads and downloads. For instance:
- Encrypt and decrypt files using the EncryptionAlgorithm and EncryptionPassword properties.
- Basic file and folder manipulation and organization using methods such as CopyResource, CreateFolder, DeleteResource, and MoveResource.
- Support for resource sharing using CreateLink, ListSharedLinks, and RevokeLink.
- Change tracking with ListChanges and WaitForChanges.
- Advanced resource listing using the Search method.
- Retrieval of account and space usage details using GetAccountInfo.
- File revision handling with ListRevisions and RestoreResource.
- And more!
Property List
The following is the full list of the properties of the component with short descriptions. Click on the links for further details.
Account | Details about the current user's account and space usage. |
Authorization | OAuth 2.0 Authorization Token. |
ChangeMarker | A marker indicating what page of changes to return next. |
DownloadType | The download type to use for file resources. |
EncryptionAlgorithm | The encryption algorithm. |
EncryptionPassword | The encryption password. |
Firewall | A set of properties related to firewall access. |
Idle | The current status of the component. |
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. |
NextChangeMarker | A marker indicating what page of changes to return in the future. |
OtherHeaders | Other headers as determined by the user (optional). |
Overwrite | Whether to overwrite the local or remote file. |
ParsedHeaders | Collection of headers returned from the last request. |
Proxy | A set of properties related to proxy access. |
QueryParams | Additional query parameters to be included in the request. |
ResourceData | The data that was downloaded, or that should be uploaded. |
ResourceMarker | A marker indicating what page of resources to return next. |
Resources | A collection of resources. |
SearchCategories | Resource categories to restrict the search to. |
SearchFileExtensions | File extensions to restrict the search to. |
SearchKind | The kind of resources to search for. |
SearchMarker | A marker indicating what page of search results to return next. |
SearchNamesOnly | Whether to match against resource names only when searching. |
SharedLinkMarker | A marker indicating what page of shared links to return next. |
SharedLinks | A collection of shared links created by the current user. |
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. |
Timeout | A timeout for the component. |
UploadSessionId | The Id of the resumable upload session. |
UseResumableUpload | Whether to use resumable uploads. |
Method List
The following is the full list of the methods of the component with short descriptions. Click on the links for further details.
AddQueryParam | Adds a query parameter to the QueryParams properties. |
Config | Sets or retrieves a configuration setting. |
CopyResource | Copies a resource. |
CreateFolder | Creates a new folder resource. |
CreateLink | Creates a shared link for a resource. |
DeleteResource | Deletes a resource. |
DownloadFile | Downloads a file resource. |
GetAccountInfo | Gets information about the current user's account and space usage. |
GetCurrentChangeMarker | Gets the most current change marker. |
GetResourceInfo | Gets information about a specific resource. |
Interrupt | Interrupt the current method. |
ListChanges | Lists changes to resources. |
ListResources | Lists resources. |
ListRevisions | Lists revisions for a file path or file resource Id. |
ListSharedLinks | Lists shared links created by the current user. |
MoveResource | Moves a resource. |
Reset | Resets the component to its initial state. |
RestoreResource | Restores a given file resource revision. |
RevokeLink | Revokes a shared link. |
Search | Searches for resources. |
SendCustomRequest | Sends a custom request to the Dropbox API. |
SetDownloadStream | Sets the stream to which downloaded data will be written. |
SetUploadStream | Sets the stream from which data is read when uploading. |
UploadFile | Uploads a file resource. |
WaitForChanges | Waits a certain amount of time for changes to occur. |
Event List
The following is the full list of the events fired by the component 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 | Fires after each fragment of a resumable upload is completed. |
Header | Fired every time a header line comes in. |
Log | Fires once for each log message. |
Progress | Fires during an upload or download to indicate transfer progress. |
ResourceList | Fires once for each resource returned when listing resources, changes, or revisions. |
SharedLinkList | Fires once for each shared link returned when listing shared links. |
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). |
Configuration Settings
The following is a list of configuration settings for the component with short descriptions. Click on the links for further details.
AccountHomeNamespace | The current user's home namespace Id. |
AccountHomePath | The path for the current user's home directory, if their account is part of a team. |
AccountRootNamespace | The current user's root namespace Id. |
AccumulatePages | Whether the component should accumulate subsequent pages of results when listing them. |
AllowCopySharedFolders | Whether to allow the copying of shared folders or their contents. |
AllowFolderDownloads | Whether to allow folder downloading. |
AllowOwnershipTransfers | Whether to allow move operations that would result in ownership transfers. |
ClientModifiedTime | The client-side last modified time. |
CreateLinkExpiration | The expiration date to assign to the link. |
CreateLinkPassword | The password to protect the link with. |
CreateLinkVisibility | The visibility to create links with. |
DateFormat | The format to use for date and time. |
DownloadTempFile | The temporary file used when downloading encrypted data. |
EncryptionIV | The initialization vector to be used for encryption/decryption. |
EncryptionKey | The key to use during encryption/decryption. |
FragmentSize | The fragment size. |
IfRevision | A revision Id, used to modify certain requests. |
IncludeDeleted | Whether deleted resources should be included in the results. |
IncludeMounted | Whether to include resources in mounted folders in the results. |
ListRevisionsMode | Controls the revision listing mode that the server should use. |
MaxResults | Limits the number of resource and change results. |
MaxRevisionResults | Limits the number of revision results. |
MaxSearchResults | Limits the number of search results. |
MuteFileUploads | Whether the server should suppress file change notifications. |
PermanentlyDelete | Whether resources should be permanently deleted (Dropbox Business only). |
ProgressAbsolute | Whether the component should track transfer progress absolutely. |
ProgressStep | How often the progress event should be fired, in terms of percentage. |
RawRequest | Returns the data that was sent to the server. |
RawResponse | Returns the data that was received from the server. |
RecurseSubfolders | Whether to recursively list all resources within the specified folder. |
RenameIfExists | Whether to rename newly-created resources in the event of a name conflict. |
TempPath | The path to the directory where temporary files are created. |
ThumbnailFormat | The image format thumbnails should be downloaded in. |
ThumbnailMode | The mode the server should use to create thumbnails. |
ThumbnailSize | The thumbnail output size. |
XChildCount | The number of child elements of the current element. |
XChildName[i] | The name of the child element. |
XChildXText[i] | The inner text of the child element. |
XElement | The name of the current element. |
XParent | The parent of the current element. |
XPath | Provides a way to point to a specific element in the returned XML or JSON response. |
XSubTree | A snapshot of the current element in the document. |
XText | The text of the current element. |
AcceptEncoding | Used to tell the server which types of content encodings the client supports. |
AllowHTTPCompression | This property enables HTTP compression for receiving data. |
AllowHTTPFallback | Whether HTTP/2 connections are permitted to fallback to HTTP/1.1. |
AllowNTLMFallback | Whether to allow fallback from Negotiate to NTLM when authenticating. |
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. |
ChunkSize | Specifies the chunk size in bytes when using chunked encoding. |
CompressHTTPRequest | Set to true to compress the body of a PUT or POST request. |
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. |
HTTP2HeadersWithoutIndexing | HTTP2 headers that should not update the dynamic header table with incremental indexing. |
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. |
KerberosSPN | The Service Principal Name for the Kerberos Domain Controller. |
LogLevel | The level of detail that is logged. |
MaxHeaders | Instructs component to save the amount of headers specified that are returned by the server after a Header event has been fired. |
MaxHTTPCookies | Instructs component to save the amount of cookies specified that are returned by the server when a SetCookie event is fired. |
MaxRedirectAttempts | Limits the number of redirects that are followed in a request. |
NegotiatedHTTPVersion | The negotiated HTTP version. |
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. |
SentHeaders | The full set of headers as sent by the client. |
StatusLine | The first line of the last response from the server. |
TransferredData | The contents of the last response from the server. |
TransferredDataLimit | The maximum number of incoming bytes to be stored by the component. |
TransferredHeaders | The full set of headers as received from the server. |
TransferredRequest | The full request as sent by the client. |
UseChunkedEncoding | Enables or Disables HTTP chunked encoding for transfers. |
UseIDNs | Whether to encode hostnames to internationalized domain names. |
UsePlatformDeflate | Whether to use the platform implementation to decompress compressed responses. |
UsePlatformHTTPClient | Whether or not to use the platform HTTP client. |
UserAgent | Information about the user agent (browser). |
CloseStreamAfterTransfer | If true, the component will close the upload or download stream after the transfer. |
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). |
FirewallListener | If true, the component binds to a SOCKS firewall as a server (IPPort only). |
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. |
KeepAliveInterval | The retry interval, in milliseconds, to be used when a TCP keep-alive packet is sent and no response is received. |
KeepAliveTime | The inactivity time in milliseconds before a TCP keep-alive packet is sent. |
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 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. |
ProxyExceptionsList | A semicolon separated list of hosts and IPs to bypass when using a proxy. |
TCPKeepAlive | Determines whether or not the keep alive socket option is enabled. |
TcpNoDelay | Whether or not to delay when sending packets. |
UseIPv6 | Whether to use IPv6. |
UseNTLMv2 | Whether to use NTLM V2. |
CACertFilePaths | The paths to CA certificate files when using Mono on Unix/Linux. |
LogSSLPackets | Controls whether SSL packets are logged when using the internal security API. |
ReuseSSLSession | Determines if the SSL session is reused. |
SSLCACerts | A newline separated list of CA certificate to use during SSL client authentication. |
SSLCheckCRL | Whether to check the Certificate Revocation List for the server certificate. |
SSLCipherStrength | The minimum cipher strength used for bulk encryption. |
SSLEnabledCipherSuites | The cipher suite to be used in an SSL negotiation. |
SSLEnabledProtocols | Used to enable/disable the supported security protocols. |
SSLEnableRenegotiation | Whether the renegotiation_info SSL extension is supported. |
SSLIncludeCertChain | Whether the entire certificate chain is included in the SSLServerAuthentication event. |
SSLNegotiatedCipher | Returns the negotiated ciphersuite. |
SSLNegotiatedCipherStrength | Returns the negotiated ciphersuite strength. |
SSLNegotiatedCipherSuite | Returns the negotiated ciphersuite. |
SSLNegotiatedKeyExchange | Returns the negotiated key exchange algorithm. |
SSLNegotiatedKeyExchangeStrength | Returns the negotiated key exchange algorithm strength. |
SSLNegotiatedVersion | Returns the negotiated protocol version. |
SSLProvider | The name of the security provider to use. |
SSLSecurityFlags | Flags that control certificate verification. |
SSLServerCACerts | A newline separated list of CA certificate to use during SSL server certificate validation. |
TLS12SignatureAlgorithms | Defines the allowed TLS 1.2 signature algorithms when UseInternalSecurityAPI is True. |
TLS12SupportedGroups | The supported groups for ECC. |
TLS13KeyShareGroups | The groups for which to pregenerate key shares. |
TLS13SignatureAlgorithms | The allowed certificate signature algorithms. |
TLS13SupportedGroups | The supported groups for (EC)DHE key exchange. |
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. |
BuildInfo | Information about the product's build. |
GUIAvailable | Tells the component whether or not a message loop is available for processing events. |
LicenseInfo | Information about the current license. |
UseInternalSecurityAPI | Tells the component whether or not to use the system security libraries or an internal implementation. |