Problem description
The object you are trying to write already exists in the bucket.
Causes
OSS returns this error when you call PutObject or CopyObject, and the x-oss-forbid-overwrite request header is set to true. When this header is enabled, OSS refuses to overwrite an existing object with the same name.
Examples
The following request triggers this error because x-oss-forbid-overwrite is set to true and an object named object-exist.txt already exists in examplebucket:
PUT /object-exist.txt HTTP/1.1
Content-Length: ContentLength
Content-Type: ContentType
Host: examplebucket.oss-cn-hangzhou.aliyuncs.com
Date: GMT Date
Authorization: SignatureValue
x-oss-forbid-overwrite: trueSolutions
Choose one of the following approaches based on your use case:
Check whether the object exists first: Call HeadObject. If OSS returns HTTP 404, the object does not exist and the write operation will succeed.
Overwrite the existing object: Remove
x-oss-forbid-overwritefrom your request, or set it tofalse.Keep both versions: Enable versioning for the bucket so that a new version is created on each write instead of overwriting the existing object. For more information, see Enable versioning.