CloudFilesProviderCreateObjectFromFile Method |
Namespace: net.openstack.Providers.Rackspace
public void CreateObjectFromFile( string container, string filePath, string objectName = null, string contentType = null, int chunkSize = 4096, Dictionary<string, string> headers = null, string region = null, Action<long> progressUpdated = null, bool useInternalUrl = false, CloudIdentity identity = null )
Exception | Condition |
---|---|
ArgumentNullException |
If container is .
-or- If filePath is . |
ArgumentException |
If container is empty.
-or- If filePath is empty. -or- If headers contains two equivalent keys when compared using OrdinalIgnoreCase. |
ContainerNameException | If container is not a valid container name. |
ObjectNameException | If objectName is not a valid object name. |
ArgumentOutOfRangeException | If chunkSize is less than 0. |
FileNotFoundException | If the file filePath could not be found. |
NotSupportedException |
If the provider does not support the given identity type.
-or- The specified region is not supported. -or- useInternalUrl is and the provider does not support internal URLs. |
InvalidOperationException |
If identity is and no default identity is available for the provider.
-or- If region is and no default region is available for the provider. |
ResponseException | If the REST API request failed. |
The content type for the object may be specified by providing the contentType argument, or by setting DetectContentType to True in the headers argument. If neither of these is used, the resulting content type of the object is unspecified.
Object metadata can be set at the time the object is created by including the custom metadata items in the headers argument. Note that unlike the UpdateObjectMetadata(String, String, DictionaryString, String, String, Boolean, CloudIdentity) method, the keys of all custom metadata items included as headers must be prefixed with ObjectMetaDataPrefix.
public void CreateObjectWithMetadata( IObjectStorageProvider provider, string containerName, string objectName, string filePath) { // Method 1: Set metadata when the object is created var headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) { { CloudFilesProvider.ObjectMetaDataPrefix + "Key", "Value" } }; provider.CreateObjectFromFile(containerName, filePath, objectName, headers: headers); // Method 2: Set metadata in a separate call after the object is created provider.CreateObjectFromFile(containerName, filePath, objectName); var metadata = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) { { "Key", "Value" } }; provider.UpdateObjectMetadata(containerName, objectName, metadata); }