无法将 "save button (by google drive)" 用于数据或 blob 源
Unable to use "save button (by google drive)" with data or blob source
我想将文档保存到 google 驱动器,该文档是在我的 Web 应用程序的客户端实时创建的,使用 google 驱动器保存按钮,但根本不起作用.
这是我从那里获取的保存静态文件的示例:https://developers.google.com/drive/v3/web/savetodrive 并且有效
<script src="https://apis.google.com/js/platform.js" async defer></script>
<div class="g-savetodrive"
data-src="//example.com/path/to/myfile.pdf"
data-filename="My Statement.pdf"
data-sitename="My Company Name">
</div>
是的,很简单,
但是如果我尝试使用数据或 blob 字段设置数据源,它无法保存或出现错误
<div class="g-savetodrive"
data-src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAKCAYAAABmBXS+AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAjSURBVChTY/y/7uR/BgKACUrjBSNc0f8AU/yKQAp+/vzJAABYKgl8odPr0gAAAABJRU5ErkJggg=="
data-filename="My Statement.pdf"
data-sitename="My Company Name">
</div>
在这里尝试 "live" 版本: https://jsbin.com/horopel/edit?html,js,console,output
blob 是同一个东西,不行,有什么解决办法吗?如果 Reactjs 解决方案更好,但欢迎任何想法。
回答: save button不支持blob源
直接来自您链接的 documentation
Requests for files on different servers are subject to Cross Origin
Resource Sharing (CORS) restrictions.
1.The data-src URL can be served from the same domain, subdomain, and protocol as the domain where the button is hosted.
Be sure to use matching protocols between the page and the data
source.
To serve the file when the same page is served by both http and https,
specify the resource without a protocol such as
data-src="//example.com/files/file.pdf", which uses the appropriate
protocol based on how the hosting page was accessed.
如您所见,它一定是一个文件。您不能只向它发送文件本身的字符串值。您是否考虑过 Google drive API 直接上传文件作为流?
我想将文档保存到 google 驱动器,该文档是在我的 Web 应用程序的客户端实时创建的,使用 google 驱动器保存按钮,但根本不起作用.
这是我从那里获取的保存静态文件的示例:https://developers.google.com/drive/v3/web/savetodrive 并且有效
<script src="https://apis.google.com/js/platform.js" async defer></script>
<div class="g-savetodrive"
data-src="//example.com/path/to/myfile.pdf"
data-filename="My Statement.pdf"
data-sitename="My Company Name">
</div>
是的,很简单,
但是如果我尝试使用数据或 blob 字段设置数据源,它无法保存或出现错误
<div class="g-savetodrive"
data-src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAKCAYAAABmBXS+AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAjSURBVChTY/y/7uR/BgKACUrjBSNc0f8AU/yKQAp+/vzJAABYKgl8odPr0gAAAABJRU5ErkJggg=="
data-filename="My Statement.pdf"
data-sitename="My Company Name">
</div>
在这里尝试 "live" 版本: https://jsbin.com/horopel/edit?html,js,console,output
blob 是同一个东西,不行,有什么解决办法吗?如果 Reactjs 解决方案更好,但欢迎任何想法。
回答: save button不支持blob源
直接来自您链接的 documentation
Requests for files on different servers are subject to Cross Origin Resource Sharing (CORS) restrictions.
1.The data-src URL can be served from the same domain, subdomain, and protocol as the domain where the button is hosted.
Be sure to use matching protocols between the page and the data source.
To serve the file when the same page is served by both http and https, specify the resource without a protocol such as data-src="//example.com/files/file.pdf", which uses the appropriate protocol based on how the hosting page was accessed.
如您所见,它一定是一个文件。您不能只向它发送文件本身的字符串值。您是否考虑过 Google drive API 直接上传文件作为流?