public function testGetDefaultBucketNameNotSet() { $req = new \google\appengine\files\GetDefaultGsBucketNameRequest(); $resp = new \google\appengine\files\GetDefaultGsBucketNameResponse(); $this->apiProxyMock->expectCall("file", "GetDefaultGsBucketName", $req, $resp); $bucket = BlobstoreService::getDefaultGoogleStorageBucketName(); $this->assertEquals($bucket, ""); $this->apiProxyMock->verify(); }
/** * Create an absolute URL that can be used by a user to asynchronously upload * a large blob. Upon completion of the upload, a callback is made to the * specified URL. * * @param string $success_path A relative URL which will be invoked after the * user successfully uploads a blob. * @param mixed[] $options A key value pair array of upload options. Valid * options are: * - max_bytes_per_blob: an integer value of the largest size that any one * uploaded blob may be. Default value: unlimited. * - max_bytes_total: an integer value that is the total size that sum of all * uploaded blobs may be. Default value: unlimited. * - gs_bucket_name: a string that is the name of a Google Cloud Storage * bucket that the blobs should be uploaded to. Not specifying a value * will result in the blob being uploaded to the application's default * bucket. * * @return string The upload URL. * * @throws InvalidArgumentException If $success_path is not valid, or one of * the options is not valid. * @throws BlobstoreException Thrown when there is a failure using the * blobstore service. */ public static function createUploadUrl($success_path, $options = array()) { $req = new CreateUploadURLRequest(); $resp = new CreateUploadURLResponse(); if (!is_string($success_path)) { throw new \InvalidArgumentException('$success_path must be a string'); } $req->setSuccessPath($success_path); if (array_key_exists('max_bytes_per_blob', $options)) { $val = $options['max_bytes_per_blob']; if (!is_int($val)) { throw new \InvalidArgumentException('max_bytes_per_blob must be an integer'); } if ($val < 1) { throw new \InvalidArgumentException('max_bytes_per_blob must be positive.'); } $req->setMaxUploadSizePerBlobBytes($val); } if (array_key_exists('max_bytes_total', $options)) { $val = $options['max_bytes_total']; if (!is_int($val)) { throw new \InvalidArgumentException('max_bytes_total must be an integer'); } if ($val < 1) { throw new \InvalidArgumentException('max_bytes_total must be positive.'); } $req->setMaxUploadSizeBytes($val); } if (array_key_exists('gs_bucket_name', $options)) { $val = $options['gs_bucket_name']; if (!is_string($val)) { throw new \InvalidArgumentException('gs_bucket_name must be a string'); } $req->setGsBucketName($val); } else { $bucket = BlobstoreService::getDefaultGoogleStorageBucketName(); if (!$bucket) { throw new \InvalidArgumentException('Application does not have a default Cloud Storage Bucket, ' . 'gs_bucket_name must be specified'); } $req->setGsBucketName($bucket); } $extra_options = array_diff(array_keys($options), self::$create_upload_url_options); if (!empty($extra_options)) { throw new \InvalidArgumentException('Invalid options supplied: ' . implode(',', $extra_options)); } try { ApiProxy::makeSyncCall('blobstore', 'CreateUploadURL', $req, $resp); } catch (ApplicationError $e) { throw BlobstoreService::ApplicationErrorToException($e); } return $resp->getUrl(); }