Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google app engine 无法从google云存储下载文档_Google App Engine_Google Cloud Storage - Fatal编程技术网

Google app engine 无法从google云存储下载文档

Google app engine 无法从google云存储下载文档,google-app-engine,google-cloud-storage,Google App Engine,Google Cloud Storage,我可以使用java中的httpclient从google云存储上传文档并下载签名url的文档。但是,当我将相同的签名url放在浏览器中时,我无法下载链接的文档。我遇到以下错误 我们计算的请求签名与您的签名不匹配 假如检查您的Google密钥和签名方法` 但是,当我在storage browser中选中check shared Public复选框时,我可以从生成的签名url下载文档。但我希望允许用户从浏览器下载文档,而无需将其标记为shared Public。 . 我想确认一些令人困惑的部分,比如

我可以使用java中的httpclient从google云存储上传文档并下载签名url的文档。但是,当我将相同的签名url放在浏览器中时,我无法下载链接的文档。我遇到以下错误

我们计算的请求签名与您的签名不匹配 假如检查您的Google密钥和签名方法`

但是,当我在storage browser中选中check shared Public复选框时,我可以从生成的签名url下载文档。但我希望允许用户从浏览器下载文档,而无需将其标记为shared Public。 . 我想确认一些令人困惑的部分,比如

若要让创建签名url后没有google帐户的用户访问文档,我还必须选中存储浏览器中的“公开共享”复选框?

但我认为,如果url被签名,那么就不应该选中“公共共享”复选框,并且没有google帐户的用户可以访问该文档?但在我的情况下,这不会发生。根据链接 它讨论规范化的\u扩展\u头 请求.addHeader(“x-goog-acl”,“公共读取”)

这是我的密码

 // construct URL
        String url = "https://storage.googleapis.com/" + bucket + filename +
                "?GoogleAccessId=" + GOOGLE_ACCESS_ID +
                "&Expires=" + expiration +
                "&Signature=" + URLEncoder.encode(signature, "UTF-8");
        System.out.println(url);
        HttpClient client = new DefaultHttpClient();
        HttpPut request = new HttpPut(url);
        request.addHeader("Content-Type", contentType);
        request.addHeader("x-goog-acl","public-read");// when i put this i get error 
        request.addHeader("Authorization","OAuth 1/zVNpoQNsOSxZKqOZgckhpQ");




        request.setEntity(new ByteArrayEntity(data));

        HttpResponse response = client.execute(request); 
当我放入request.addHeader(“x-goog-acl”,“public read”);我犯了一个错误 HTTP/1.1 403禁止的错误。 .但当我删除这行时,它已成功上载。似乎我需要设置 request.addHeader(“x-goog-acl”,“public read”)使其可公开访问,但在我的代码中添加此内容时,我会遇到错误


.有什么建议吗?

终于解决了。

要从浏览器运行单一url,您必须设置HTTP头。在

内容类型可选。如果提供此值,客户端(浏览器)必须将此HTTP头设置为相同的值。有一个单词most

因此,如果要为符号字符串提供内容类型,则必须在浏览器http标头中提供相同的内容类型。当我在浏览器标头中设置内容类型时,此错误最终解决了

这对我来说很有效:

    set_include_path("../src/" . PATH_SEPARATOR . get_include_path());
    require_once 'Google/Client.php';

    function signed_storageURL($filename, $bucket, $p12_certificate_path, $access_id,         $method = 'GET', $duration = 3600 ) 
    { 
        $expires = time( ) + $duration*60; 
        $content_type = ($method == 'PUT') ? 'application/x-www-form-urlencoded' : ''; 
        $to_sign = ($method."\n"."\n".$content_type."\n".$expires."\n".'/'.$bucket.'/'.$filename); 
        $signature = '';

                $signer = new Google_Signer_P12(file_get_contents($p12_certificate_path), 'notasecret');
        $signature = $signer->sign($to_sign);
        $signature = urlencode( base64_encode( $signature ) );

        return ('https://'.$bucket.'.commondatastorage.googleapis.com/'.$filename.'?GoogleAccessId='.$access_id.'&Expires='.$expires.'&Signature='.$signature); 
    }

    $url = signed_storageURL(rawurlencode("áéíóú espaço & test - =.jpg"),'mybucket', 'mykey.p12','myaccount@developer.gserviceaccount.com');
    echo '<a href="'.$url.'">'.$url.'</a>';
set_include_path(“../src/”.path_SEPARATOR.get_include_path());
需要一次“Google/Client.php”;
函数签名存储URL($filename、$bucket、$p12\u certificate\u path、$access\u id、$method='GET',$duration=3600)
{ 
$expires=time()+$duration*60;
$content_type=($method=='PUT')?'application/x-www-form-urlencoded':'';
$to\u sign=($method.\n“.”\n“.”$content\u type“.\n“$expires。”\n“/”.$bucket./”.$filename);
$signature='';
$signer=newgoogle\u signer\u P12(文件获取内容($P12\u证书路径),'notasecret');
$signature=$signer->sign($to_sign);
$signature=urlencode(base64_encode($signature));
返回('https://'.$bucket.'.commondatastorage.googleapis.com/'.$filename.'?GoogleAccessId='.$access\u id.&Expires='.$Expires.&Signature='.$Signature');
}
$url=signed_storageURL(rawurlencode(“áèíóúespaço&test-=.jpg”)、'mybucket'、'mykey.p12'、'myaccount@developer.gserviceaccount.com');
回声';