Upload objects to OSS from a Swift application using the PutObject API.
Prerequisites
Before you begin, ensure that you have:
An OSS bucket
The
oss:PutObjectpermission. For setup instructions, see Grant custom policies to RAM usersThe
OSS_ACCESS_KEY_IDandOSS_ACCESS_KEY_SECRETenvironment variables set with your credentials
Usage notes
The sample code uses
cn-hangzhouas the region. Replace it with the region where your bucket is located. For region IDs and endpoint mappings, see Regions and endpoints.By default, the public endpoint is used. To access OSS from another Alibaba Cloud service in the same region, use the internal endpoint instead.
Versioning behavior
The upload behavior depends on whether versioning is enabled on the bucket.
| Bucket state | Version ID | Same-name object behavior |
|---|---|---|
| Versioning enabled | Unique version ID, returned in the x-oss-version-id response header | Both versions are retained |
| Versioning suspended | "null" | New object overwrites the previous one; only one version can have a "null" version ID |
What's next
该文章对您有帮助吗?