Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Cloud Storage bucket upload byte with create or write function

Hi there,

On a Bucket storage, does anyone know which function is better for uploading an "byteArray"?
I have managed to implemented with "write(...)" and "create(...)".

Despite "create(...)" being faster (more than 3x faster), I think I might have some issues with it and that the "write(...)" is safer and more recommended for uploading data.

Does anyone know the real difference between both, or point me into the correct documentation page, where I can find that difference (have searched for it, but didn't found anything conclusive).

2 1 345
1 REPLY 1

The main difference between `write(...)` and `create(...)` methods for uploading a byte array to Google Cloud Storage lies in their implementation and performance characteristics.

`create(...)`
- Method: `create(blobInfo, byteArray)`
- Performance: Typically faster because it creates the blob in a single step.
- Use Case: Recommended for simple, straightforward uploads where speed is a priority.

`write(...)`
- Method: `write(blobId, byteArray)`
- Performance: Slower because it involves writing to an existing blob and may handle additional checks or buffering.
- Use Case: Safer for more complex scenarios where you need fine-grained control over the writing process.

Recommendation
If you are prioritizing speed and have a straightforward upload scenario, `create(...)` is suitable. However, for more control and potentially safer handling of data, `write(...)` may be preferable.

Documentation
For detailed information, refer to the [Google Cloud Storage Client Libraries documentation](https://cloud.google.com/storage/docs/reference/libraries).

In summary:
- Use `create(...)` for faster uploads if your use case is straightforward.
- Use `write(...)` for potentially safer uploads when you need more control.