2016-11-16 96 views
0

我试图使用“保存到云端硬盘”按钮,谷歌提供了使驱动器上传更加容易,它看起来像这样:Google Drive与Laravel保存在一起吗?

<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> 

我的问题是,因为我使用Laravel和php artisan serve命令为我的项目服务,我该怎么写我的文件的路径?它位于'Project name'/ storage/app/docs /中,我试过//storage/app/docs/{{ $file->path }},但它不起作用,并且使用storage_path()并没有改变任何东西。我在这里错过了什么?

编辑: 我尝试使用另一个文件,其中一个托管在别处。所以我启用CORS在我的项目,并使用邮差,我测试看标题我用的是:

Access-Control-Allow-Headers →Content-Type, X-Auth-Token, Origin, Range 

Access-Control-Allow-Methods →POST, GET, OPTIONS, PUT, DELETE 

Access-Control-Allow-Origin →* 

Access-Control-Expose-Headers →Cache-Control, Content-Encoding, Content-Range 

按照谷歌文档,应该现在的工作,但事实并非如此。 这是我收到的控制台错误:

Response to preflight request doesn't pass access control check: 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://localhost:8000' is therefore not allowed access. 
The response had HTTP status code 400. 

而且我oficially的想法。

+0

''//在'//例子。 com/.....“仅仅是”现在正在使用的任何协议“的简称。请参阅[此问题](http://stackoverflow.com/a/9646435/605707)了解更多信息。 – deefour

+0

我现在明白了,但我仍然使用Laravel的'asset()'函数(它应该自动解析请求方案)并且它仍然不起作用,我只是得到一个“失败的下载XHR错误” –

+0

无论asset()'的行为如何,你不能指向HTML根目录之外的文件。浏览器只能在您的Laravel应用的公共/文件夹中发送请求。阅读** Public Disk部分[在这些文档](https://laravel.com/docs/5.3/filesystem#configuration)以了解更多关于'storage/app/docs /'目录应该如何符号链接到'public /'。 – deefour

回答

0

正如文件规定 - Troubleshooting

如果您下载资料,src网址时,得到一个XHR错误,验证该资源确实存在,而且你没有CORS问题。

如果保存到驱动器按钮适用于除Internet Explorer 9以外的所有浏览器,则可能需要将浏览器配置为启用默认禁用的CORS

如果大文件被截断为2MB,很可能是您的服务器未公开Content-Range,可能是CORS问题。

注意对相关SO问题的答案 - Save To Drive Button Doesn't Workdocumentation是:

data-src URL可以从另一个域服务,但来自HTTP服务器的响应需要支持HTTP OPTION请求,其中包括以下特殊的HTTP标头:

Access-Control-Allow-Origin: * 
Access-Control-Allow-Headers: Range 
Access-Control-Expose-Headers: Cache-Control, Content-Encoding, Content-Range