0

I'm trying to use the "Save to drive" button that Google provides to make Drive uploads even easier, it looks like this:

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

My question is, since I am using Laravel and the php artisan serve command to serve my project, how am I supposed to write the path to my file? It's located at 'Project name'/storage/app/docs/, I've tried //storage/app/docs/{{ $file->path }} but it doesn't work, and using storage_path() didn't change anything. What am I missing here?

EDIT: I tried using another file, one that was hosted somewhere else. So I enabled CORS on my project and, using Postman, I tested to see the headers I was using:

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

According to the Google documentation, it should be working now, yet it's not. This is the error that I'm getting in the console:

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.

And I'm oficially out of ideas.

S.A.Th.
  • 53
  • 2
  • 10
  • `//` in `//example.com/.....` is just short for "whatever protocol is being used right now". See [this question](http://stackoverflow.com/a/9646435/605707) for more info. – deefour Nov 16 '16 at 22:32
  • I understand now, but still, I used Laravel's `asset()` function (which is supposed to resolve the scheme of requests automatically) and it still doesn't work, I just get a "Failed Download XHR error" – S.A.Th. Nov 16 '16 at 22:46
  • Regardless of how `asset()` behaves, you cannot point at files outside the web root from within your HTML. The browser can only make requests to stuff within your Laravel app's public/ folder. Read **The Public Disk** section [in these docs](https://laravel.com/docs/5.3/filesystem#configuration) to learn more about how your `storage/app/docs/` directory should probably be symlinked to `public/`. – deefour Nov 17 '16 at 14:57

1 Answers1

0

As stated in the document - Troubleshooting,

If you get an XHR error when downloading your data-src URL, verify that the resource actually exists, and that you do not have a CORS issue.

If the Save to Drive button works with all browsers except Internet Explorer 9, you may need to configure your browser to enable CORS, which is disabled by default.

If large files are truncated to 2MB, it is likely that your server is not exposing Content-Range, likely a CORS issue.

Take note the answer on the related SO question - Save To Drive Button Doesn't Work and the documentation that:

The data-src URL can be served from another domain but the responses from the HTTP server needs to support HTTP OPTION requests and include the following special HTTP headers:

Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Range
Access-Control-Expose-Headers: Cache-Control, Content-Encoding, Content-Range
Community
  • 1
  • 1
Mr.Rebot
  • 6,703
  • 2
  • 16
  • 91