Storage/src/Bucket.php
public function upload($data, array $options = [])
    {
        if ($this->isObjectNameRequired($data) && !isset($options['name'])) {
            throw new \InvalidArgumentException('A name is required when data is of type string or null.');
        }

        $encryptionKey = isset($options['encryptionKey']) ? $options['encryptionKey'] : null;
        $encryptionKeySHA256 = isset($options['encryptionKeySHA256']) ? $options['encryptionKeySHA256'] : null;

        $response = $this->connection->insertObject(
            $this->formatEncryptionHeaders($options) + $this->identity + [
                'data' => $data
            ]
        )->upload();

        return new StorageObject(
            $this->connection,
            $response['name'],
            $this->identity['bucket'],
            $response['generation'],
            $response,
            $encryptionKey,
            $encryptionKeySHA256
        );
    }
public function upload($data, array $options = [])
    {
        if ($this->isObjectNameRequired($data) && !isset($options['name'])) {
            throw new \InvalidArgumentException('A name is required when data is of type string or null.');
        }

        $encryptionKey = isset($options['encryptionKey']) ? $options['encryptionKey'] : null;
        $encryptionKeySHA256 = isset($options['encryptionKeySHA256']) ? $options['encryptionKeySHA256'] : null;

        $response = $this->connection->insertObject(
            $this->formatEncryptionHeaders($options) + $this->identity + [
                'data' => $data
            ]
        )->upload();

        return new StorageObject(
            $this->connection,
            $response['name'],
            $this->identity['bucket'],
            $response['generation'],
            $response,
            $encryptionKey,
            $encryptionKeySHA256
        );
    }
public function upload ( $ data , array $ options = [ ] ) { if ( $ this -> isObjectNameRequired ( $ data ) && ! isset ( $ options [ 'name' ] ) ) { throw new \ InvalidArgumentException ( 'A name is required when data is of type string or null.' ) ; } $ encryptionKey = isset ( $ options [ 'encryptionKey' ] ) ? $ options [ 'encryptionKey' ] : null ; $ encryptionKeySHA256 = isset ( $ options [ 'encryptionKeySHA256' ] ) ? $ options [ 'encryptionKeySHA256' ] : null ; $ response = $ this -> connection -> insertObject ( $ this -> formatEncryptionHeaders ( $ options ) + $ this -> identity + [ 'data' => $ data ] ) -> upload ( ) ; return new StorageObject ( $ this -> connection , $ response [ 'name' ] , $ this -> identity [ 'bucket' ] , $ response [ 'generation' ] , $ response , $ encryptionKey , $ encryptionKeySHA256 ) ; }
Upload your data in a simple fashion. Uploads will default to being
resumable if the file size is greater than 5mb.

Example:
```
$object = $bucket->upload(
fopen(__DIR__ . '/image.jpg', 'r')
);
```

```
// Upload an object in a resumable fashion while setting a new name for
// the object and including the content language.
$options = [
'resumable' => true,
'name' => '/images/new-name.jpg',
'metadata' => [
'contentLanguage' => 'en'
]
];

$object = $bucket->upload(
fopen(__DIR__ . '/image.jpg', 'r'),
$options
);
```

```
// Upload an object with a customer-supplied encryption key.
$key = base64_encode(openssl_random_pseudo_bytes(32)); // Make sure to remember your key.

$object = $bucket->upload(
fopen(__DIR__ . '/image.jpg', 'r'),
['encryptionKey' => $key]
);
```

```
// Upload an object utilizing an encryption key managed by the Cloud Key Management Service (KMS).
$object = $bucket->upload(
fopen(__DIR__ . '/image.jpg', 'r'),
[
'metadata' => [
'kmsKeyName' => 'projects/my-project/locations/kr-location/keyRings/my-kr/cryptoKeys/my-key'
]
]
);
```

@see https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload#resumable Learn more about resumable
uploads.
@see https://cloud.google.com/storage/docs/json_api/v1/objects/insert Objects insert API documentation.
@see https://cloud.google.com/storage/docs/encryption#customer-supplied Customer-supplied encryption keys.

@param string|resource|StreamInterface|null $data The data to be uploaded.
@param array $options [optional] {
Configuration options.

@type string $name The name of the destination. Required when data is
of type string or null.
@type bool $resumable Indicates whether or not the upload will be
performed in a resumable fashion.
@type bool $validate Indicates whether or not validation will be
applied using md5 hashing functionality. If true and the
calculated hash does not match that of the upstream server the
upload will be rejected.
@type int $chunkSize If provided the upload will be done in chunks.
The size must be in multiples of 262144 bytes. With chunking
you have increased reliability at the risk of higher overhead.
It is recommended to not use chunking.
@type callable $uploadProgressCallback If provided together with
$resumable == true the given callable function/method will be
called after each successfully uploaded chunk. The callable
function/method will receive the number of uploaded bytes
after each uploaded chunk as a parameter to this callable.
It's useful if you want to create a progress bar when using
resumable upload type together with $chunkSize parameter.
If $chunkSize is not set the callable function/method will be
called only once after the successful file upload.
@type string $predefinedAcl Predefined ACL to apply to the object.
Acceptable values include, `"authenticatedRead"`,
`"bucketOwnerFullControl"`, `"bucketOwnerRead"`, `"private"`,
`"projectPrivate"`, and `"publicRead"`.
@type array $metadata The full list of available options are outlined
at the [JSON API docs](https://cloud.google.com/storage/docs/json_api/v1/objects/insert#request-body).
@type array $metadata.metadata User-provided metadata, in key/value pairs.
@type string $encryptionKey A base64 encoded AES-256 customer-supplied
encryption key. If you would prefer to manage encryption
utilizing the Cloud Key Management Service (KMS) please use the
`$metadata.kmsKeyName` setting. Please note if using KMS the
key ring must use the same location as the bucket.
@type string $encryptionKeySHA256 Base64 encoded SHA256 hash of the
customer-supplied encryption key. This value will be calculated
from the `encryptionKey` on your behalf if not provided, but
for best performance it is recommended to pass in a cached
version of the already calculated SHA.
}
@return StorageObject
@throws \InvalidArgumentException
Upload your data in a simple fashion . Uploads will default to being resumable if the file size is greater than 5mb .