简体   繁体   English

我应该如何配置 Javascript Webapp 以便它可以使用 Web 浏览器查看 Google 云存储中的文件

[英]How should I configure a Javascript Webapp so that it can use a Web Browser to view files in Google Cloud storage

My Javascript Webapp enables logged-in users to upload PDF files into the Google Cloud and store them in a Cloud Storage bucket. My Javascript Webapp 使登录的用户能够将 PDF 文件上传到 Google Cloud 并将它们存储在 Cloud Storage 存储桶中。 I'd like the wider public to be able to view the files they've just uploaded, but this is proving more difficult than I expected.我希望广大公众能够查看他们刚刚上传的文件,但事实证明这比我预期的要困难。

An HTML button firing an onclick function for a window.open call hard-coded with an HREF referencing the full Cloud Storage URL for the file together with an access token does the trick.一个 HTML 按钮为window.open调用触发 onclick 函数,使用 HREF 硬编码引用文件的完整 Cloud Storage URL 以及访问令牌就可以了。 I can get this information from the Storage tab in the Firebase console, but I'm at a loss to find a way of configuring this arrangement dynamically.我可以从 Firebase 控制台的“存储”选项卡中获取此信息,但我无法找到动态配置此安排的方法。

The URL part doesn't seem to be a problem, but I would appreciate advice on how I can obtain a suitable access token. URL 部分似乎不是问题,但我希望获得有关如何获得合适的访问令牌的建议。

Alternatively, can anyone suggest how I might lower the bar on GCP security settings for my Cloud Storage files so that a casual user doesn't need a token in the first place?或者,任何人都可以建议我如何降低我的云存储文件的 GCP 安全设置标准,以便临时用户首先不需要令牌? I have tried using the Cloud Security console to set permissions but have still to find a combination of settings that gives the desired outcome.我曾尝试使用 Cloud Security 控制台设置权限,但仍需找到可提供所需结果的设置组合。

The answer is provided by Google's Make data public document.答案由 Google 的Make data public文档提供。

This tells you how to make either individual files or the entire content of a bucket publicly readable.这告诉您如何使单个文件或存储桶的全部内容公开可读。

In my case, the second approach was clearly what I needed.就我而言,第二种方法显然是我需要的。 I created a new bucket specifically for the content I wanted to share and followed the instructions closely - they're complex and easily misunderstood.我专门为我想要分享的内容创建了一个新的存储桶,并严格按照说明进行操作——它们很复杂,很容易被误解。 At several points, you need to select settings from drop-down lists but, while these lists are populated, you don't see the items you're looking for until you start typing in the keywords detailed in the instructions.在某些情况下,您需要从下拉列表中选择设置,但是当这些列表被填充时,在您开始输入说明中详述的关键字之前,您看不到要查找的项目。

With the new permission in place, my files were accessible by URLs of the form https://storage.googleapis.com/[Bucket name]/[File name]有了新的权限,我的文件可以通过https://storage.googleapis.com/[Bucket name]/[File name] 形式的 URL 访问

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在没有 JavaScript 令牌的情况下将文件上传到谷歌云存储 - How can I upload files to google cloud storage without token in JavaScript 如何使用 JavaScript 更新 Google Cloud Storage 中的文件 - How to update files in Google Cloud Storage with JavaScript 我应该将Google Web Toolkit用于我的新网络应用吗? - Should I use Google Web Toolkit for my new webapp? 如何将Google Cloud Storage用于javascript - how to use google cloud storage for javascript 如何将CSV文件导入到Webapp的javascript中,以便我可以在Google Maps画布上放置地址标记? - How do import a CSV file into the javascript for a webapp so that i can place address markers on a google maps canvas? Google Cloud Storage - 如何直接从浏览器上传内容 (JavaScript) - Google Cloud Storage - How to Upload content directly from browser (JavaScript) 如何将动态 IP 地址添加到 Google Cloud 中的“授权 javascript 来源”列表中,以便将 Google 登录集成到我的 web 应用程序中? - How can I add a dynamic IP address to the "Authorised javascript origins" list in Google Cloud so that I can integrate Google sign-in into my web app? 我如何使用HTML,JavaScript Web存储作为登录脚本 - How can i use the html, javascript web storage for login script 如何通过在WebApp中显示并创建指向存储在计算机中的本地文件的链接来在Web浏览器中查看本地文件? - How to view local files in web browser by displaying and creating a link to local files stored in your computer in your webApp? 如何配置Oracle WebCenter Portal项目,以便无需重新启动服务器即可添加JavaScript文件? - How to configure Oracle WebCenter Portal Project so that I can add JavaScript files without having to restart the server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM