Click or drag to resize
IObjectStorageProviderCreateObject Method
Creates an object using data from a Stream. If the destination file already exists, the contents are overwritten.

Namespace: net.openstack.Core.Providers
Assembly: openstacknet (in openstacknet.dll) Version: 1.7.7+Branch.master.Sha.25d803f397c8693c2c13777ef6675f796f520f2c
Syntax
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
)

Parameters

container
Type: SystemString
The container name.
stream
Type: System.IOStream
A Stream providing the data for the file.
objectName
Type: SystemString
The destination object name. Example image_name.jpeg
contentType (Optional)
Type: SystemString
The content type of the created object. If the value is or empty, the content type of the created object is unspecified.
chunkSize (Optional)
Type: SystemInt32
The buffer size to use for copying streaming data.
headers (Optional)
Type: System.Collections.GenericDictionaryString, String
A collection of custom HTTP headers to associate with the object (see GetObjectHeaders(String, String, String, Boolean, CloudIdentity)).
region (Optional)
Type: SystemString
The region in which to execute this action. If not specified, the user's default region will be used.
progressUpdated (Optional)
Type: SystemActionInt64
A callback for progress updates. If the value is , no progress updates are reported.
useInternalUrl (Optional)
Type: SystemBoolean
to use the endpoint's InternalURL; otherwise to use the endpoint's PublicURL.
identity (Optional)
Type: net.openstack.Core.DomainCloudIdentity
The cloud identity to use for this request. If not specified, the default identity for the current provider instance will be used.
Exceptions
ExceptionCondition
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.

ContainerNameExceptionIf container is not a valid container name.
ObjectNameExceptionIf objectName is not a valid object name.
ArgumentOutOfRangeExceptionIf 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.

ResponseExceptionIf the REST API request failed.
Remarks

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.

Examples
The following code shows two ways to create an object with custom metadata. The first uses the headers argument to this method, and the second shows an alternative method of calling UpdateObjectMetadata(String, String, DictionaryString, String, String, Boolean, CloudIdentity) after the object is created.
C#
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);
}
Version Information

.NET Framework

Supported in: 4.5

openstack.net

Supported in: 1.6, 1.5, 1.4, 1.3.6
See Also