IObjectStorageProviderCreateObject Method |
Namespace: net.openstack.Core.Providers
void CreateObject( string container, Stream stream, string objectName, string contentType = null, int chunkSize = 65536, 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 stream is . -or- If objectName is . |
ArgumentException |
If container is empty.
-or- If objectName 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. |
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, Stream data) { // Method 1: Set metadata when the object is created var headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) { { CloudFilesProvider.ObjectMetaDataPrefix + "Key", "Value" } }; provider.CreateObject(containerName, data, objectName, headers: headers); // Method 2: Set metadata in a separate call after the object is created provider.CreateObject(containerName, data, objectName); var metadata = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) { { "Key", "Value" } }; provider.UpdateObjectMetadata(containerName, objectName, metadata); }