为什么我的签名URL会出现错误403? [英] Why do my signed URLs get an error 403?

查看:286
本文介绍了为什么我的签名URL会出现错误403?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

参考: https://googlecloudplatform.github.io/google-cloud-node/#/docs/storage/0.8.0/storage/file?method=getSignedUrl



这很奇怪。

发生了什么事?



我的服务帐户设置为具有读取存储对象的权限。 server:

  snapshot.forEach(function(childSnapshot){
titleArray.push( childSnapshot.val()。title);
usernameArray.push(childSnapshot.val().username);
keyArray.push(childSnapshot.key);
var file = bucket.file( childSnapshot.val()。image);
var config = {
action:'read',
expires:Date.now()+ 10000,
contentType:'image / png'
};

file.getSignedUrl(config,function(err,url){
if(err){
console.error(err);
return;
}
imageArray.push(url);
if(imageArray.length == 9){
res.render(home ,{keyArray:keyArray,titleArray:titleArray,usernameArray:usernameArray,imageArray:imageArray});
}
});
});

客户:

  $(。homeImage)。each(function(i){
var row = $(this)
row.attr('id', i);
if(i == 4){

} else {
$(#+ i).css('background-image',url '+ imageArray [i] +'));
}
});






回应:

错误消息意味着您的请求没有任何与之关联的身份验证。对于一个签名的URL,这意味着没有设置GoogleAccessId / Signature / Expires查询参数。



我调试打印图像数组服务器端和客户端以查看编辑:在这种情况下,它看起来像& 被替换为& amp; 某处。


Reference: https://googlecloudplatform.github.io/google-cloud-node/#/docs/storage/0.8.0/storage/file?method=getSignedUrl

This is extremely strange. I did set my service account as having read permission of the storage objects.

What is going on ?

server:

snapshot.forEach(function(childSnapshot){
            titleArray.push(childSnapshot.val().title);
            usernameArray.push(childSnapshot.val().username);
            keyArray.push(childSnapshot.key);
            var file = bucket.file(childSnapshot.val().image);
            var config = {
              action: 'read',
              expires: Date.now() + 10000,
              contentType: 'image/png'
            };

            file.getSignedUrl(config, function(err, url) {
                if (err) {
                    console.error(err);
                    return;
                }
                imageArray.push(url);
                if (imageArray.length == 9) {
                    res.render("home", {keyArray: keyArray, titleArray: titleArray, usernameArray: usernameArray, imageArray: imageArray});
                }
            });
        });

client:

$(".homeImage").each(function(i) {
            var row = $(this)
            row.attr('id', i);
            if (i == 4) {

            } else {
                $("#"+i).css('background-image', "url('" + imageArray[i]  + "')");
            }
        });


Response:

This is extremely strange since I thought signed URLs were supposed to authenticate my request as being sent by my service account.

解决方案

The error message implies that your request doesn't have any authentication associated with it. For a Signed URL that would mean that the GoogleAccessId/Signature/Expires query parameters are not set.

I'd debug print the image array server side and client side to see where it is getting lost.

Edit: In this case it looks like & was being replaced with & somewhere.

这篇关于为什么我的签名URL会出现错误403?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆