PUT Object
API Description
You can use this API to upload an object to a specified bucket.
Method Definition
1. ObsClient->putObject(array $parameter) 2. ObsClient->putObjectAsync(array $parameter, callable $callback)
Request Parameter
| Field | Type | Optional or Mandatory | Description |
|---|---|---|---|
| Bucket | string | Mandatory | Bucket name |
| Key | string | Mandatory | Object name |
| ACL | string | Optional | Pre-defined access control policy specified during object creation |
| StorageClass | string | Optional | Storage class, which can be specified during the object creation |
| Body | string or resource or GuzzleHttp\Psr7\StreamInterface | Optional | Object content to be uploaded |
| SourceFile | string | Optional | Path to the source file of the object |
| Metadata | associative array | Optional | Customized metadata of the object |
| WebsiteRedirectLocation | string | Optional | Location where the object is redirected to, when the bucket is configured with website hosting. |
| ContentType | string | Optional | MIME type of the object. For details about the common content types, see Configuring, Editing, and Viewing Object Metadata. |
| ContentLength | integer | Optional | Object size in bytes |
| ContentMD5 | string | Optional | Base64-encoded MD5 value of the object data to be uploaded. It is provided for the OBS server to verify data integrity. |
| SseKms | string | Optional | Algorithm used in SSE-KMS encryption. The value can be:
|
| SseKmsKey | string | Optional | ID of the KMS master key used in SSE-KMS encryption. If this parameter is left blank, the default key is used. To obtain the key ID, see Viewing a Key. |
| SseC | string | Optional | Algorithm used in SSE-C encryption. The value can be:
|
| SseCKey | string | Optional | Custom key used in SSE-C encryption. The value is a Base64-encoded 256-bit key. |
- Body and SourceFile cannot be used together.
- If both Body and SourceFile are null, the size of the object to be uploaded is 0 bytes.
Returned Result
| Field | Type | Description |
|---|---|---|
| HttpStatusCode | integer | HTTP status code |
| Reason | string | Reason description |
| RequestId | string | Request ID returned by the OBS server |
| ObjectURL | string | Object URL |
| ETag | string | Object ETag |
| VersionId | string | Object version ID |
| StorageClass | string | Storage class of the object. When the storage class is OBS Standard, the value is null. |
| SseKms | string | Algorithm used in SSE-KMS encryption |
| SseKmsKey | string | ID of the KMS master key used in SSE-KMS encryption. If this parameter is left blank, the default key is used. To obtain the key ID, see Viewing a Key. |
| SseC | string | Algorithm used in SSE-C encryption |
| SseCKeyMd5 | string | MD5 value of the key used in SSE-C encryption |
Sample Code
try{ $resp = $obsClient -> putObject([ 'Bucket' => 'bucketname', 'Key' => 'objectkey', 'Metadata' => ['meta1' => 'value1', 'meta2' => 'value2'], // 'SourceFile' => 'localfile', 'Body' => 'Hello OBS', 'ContentType' => 'text/plain' ]); printf("RequestId:%s\n", $resp['RequestId']); printf("VersionId:%s\n", $resp['VersionId']); printf("StorageClass:%s\n", $resp['StorageClass']); printf("ETag:%s\n", $resp['ETag']); }catch (Obs\Common\ObsException $obsException){ printf("ExceptionCode:%s\n", $obsException->getExceptionCode()); printf("ExceptionMessage:%s\n", $obsException->getExceptionMessage()); }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.