谷歌云存储curl PHP上传


google cloud storage curl php upload

我正在尝试使用Curl php上传文件到谷歌云存储。

define("BASE","https://www.googleapis.com/upload/storage/v1/b/");
$key='XXXXX';
$authheaders = array(
"Authorization: Bearer " .$key,
"Content-Type: image/jpeg"
);
$bucket='gs://storage-8c79a.appspot.com';
$file='1234';
$fileName='1.pdf';
$url=BASE.$bucket.'/o?name=name_of_file.jpg&uploadType=multipart';
$curl = curl_init();
curl_setopt($curl, CURLOPT_POSTFIELDS, $file);
curl_setopt($curl, CURLOPT_HTTPHEADER, $authheaders);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_USERAGENT, "HTTP/1.1.5");
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
// 1 is CURL_SSLVERSION_TLSv1, which is not always defined in PHP.
curl_setopt($curl, CURLOPT_SSLVERSION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);

$response = curl_exec($curl);
echo $response;
输出:

HTTP/1.1 404找不到X-GUploader-UploadID: aenb2uridzxptss2gac2bvfr4b4abfkrony5gbcg8d85az3mk69yubpccp_k3cx64a2msscu - n_4f - rffe10vh_gjubrjkrkzz4nj3tlry4i8js - pguqtw Vary: Origin Vary: X-Origin Content-Type: text/html;charset=UTF-8 Content-Length: 9 Date: Tue, 23 Aug 2016 09:57:23 GMT Server: UploadServer Alternate-Protocol: 443:quic Alt-Svc: quic=":443";马= 2592000;v="35,34,33,32,31,30"未找到

请帮我解决这个问题

代码:

define("BASE","https://www.googleapis.com/upload/storage/v1/b/");
$bucket='gs://someproject.appspot.com';
$url=BASE.$bucket.'/o?name=name_of_file.jpg;

指向如下URL:

https://www.googleapis.com/upload/storage/v1/b/gs://someproject.appspot.com/o?name=name_of_file.jppg

URL的桶名部分应该只是"someproject.appspot.com"。删除"gs://"