What do I do if a function is triggered multiple times when an object is uploaded to OSS?

更新时间:
复制 MD 格式

The most likely cause is that the Trigger Event parameter uses a wildcard (oss:ObjectCreated:*). A wildcard matches every event generated during a single upload operation — not just the final "object ready" event — so a single upload triggers your function multiple times.

Replace the wildcard with the specific event types that match your upload method.

Why wildcards cause repeated triggering

A multipart upload generates multiple OSS events in sequence. When Trigger Event is set to oss:ObjectCreated:*, every one of those events invokes the function.

For example, uploading a 12 MB object using OSS Browser with a part size of 5 MB generates the following 5 events — and triggers the function 5 times:

#Event
1oss:ObjectCreated:InitiateMultipartUpload
2oss:ObjectCreated:UploadPart
3oss:ObjectCreated:UploadPart
4oss:ObjectCreated:UploadPart
5oss:ObjectCreated:CompleteMultipartUpload

Only event 5 means the object is fully available. Events 1–4 fire while the upload is still in progress.

Solution

Remove the wildcard and configure specific event types based on your upload method:

EventUpload methodDescription
oss:ObjectCreated:PutObjectSimple uploadCreates or overwrites an object by using simple uploads
oss:ObjectCreated:PostObjectForm uploadCreates or overwrites an object by using form uploads
oss:ObjectCreated:CompleteMultipartUploadMultipart uploadFires when all parts are assembled and the object is complete

For multipart uploads, set Trigger Event to oss:ObjectCreated:CompleteMultipartUpload to ensure the function runs exactly once per completed upload.

For workflows that accept objects from multiple upload methods, configure all three event types on the trigger. See OSS trigger events for the full list of supported event types.