我正在尝试使用generate_signed_url函数为用户提供私人图像。
我实现了这个功能,并且在第一次尝试时就成功了,但是一段时间后它停止工作了,我不知道为什么。
现在,当我尝试加载页面时,在所有非公开的图像上都出现403错误。
我确保项目帐户具有存储分区的所有权限,但仍然收到403错误。另外,我看不到错误的内容,它对我来说似乎是空的(也许我没有正确阅读它?)所以我不知道具体的问题。
这是我的实时测试站点:https://thawing-hamlet-36152.herokuapp.com/view_project/project/13
我添加了一段代码,这些代码生成画布并在此处加载图像。最后一行是对generate_signed_url
的调用
var canvas = document.getElementById("{{'canvas'+(blob.name).replace('/','')}}");
var ctx=canvas.getContext("2d");
var img = new Image;
{% if detections[img_count[0]]|length > 0 %}
img.onload = drawImageScaled.bind(null,img,ctx,
{{ detections[img_count[0]]["detection_boxes"][0][0] }} ,
{{ detections[img_count[0]]["detection_boxes"][0][1] }} ,
{{ detections[img_count[0]]["detection_boxes"][0][2] }} ,
{{ detections[img_count[0]]["detection_boxes"][0][3] }}
);
{% else %}
img.onload = drawImageScaled.bind(null,img,ctx, 0,0,0,0);
{% endif %}
img.src = "{{ blob.generate_signed_url(finish, method='GET') }}";
答案 0 :(得分:0)
花了我很长时间,但我找到了解决方法。
img.src =“ {{blob.generate_signed_url(finish,method ='GET')}}”“;方法是在Jinja模板中。 Jinja读取字符串时,将URL中的“&”转换为“&amp”以使其与UTF8兼容。 这样一来,Google便无法读取参数,并且该请求被解释为匿名请求。
该解决方案是通过使用Jinja |安全过滤器从网址中删除“ amp”