When to use copy API instead of rewrite API?

Viewed 105

According to the GCS documentation,

Generally, you should use the rewrite method instead of the copy method: the copy method uses the rewrite method, but calls it exactly once. Larger objects can require multiple rewrite calls, so copy attempts of such objects can lead to Payload too large errors.

Reading that it seems I should always be using the rewrite method. copy is a little easier to implement and it inherently limits the size of the object that can be copied, but as long as I've implemented rewrite anyways and I don't want GCS to limit my object size,

I'm wondering if there's any case in which using the copy method has an advantage or what scenarios should I use the copy method instead of rewrite?

1 Answers

TLDR: The copy method has no advantages over the rewrite method.

copy is meant to be used for very quick operations, or small objects, because of how it is implemented.

The copy REST API call has a known issue of DEADLINE EXCEEDED error for larger files.

For longer operations, it is recommended using rewrite instead of copy.

Related