gearbox-solutions / eloquent-filemaker

A Model extension and Eloquent driver for Laravel connecting to FileMaker through the Data API
https://gearboxgo.com
MIT License
54 stars 16 forks source link

Download a PDF file from a container #63

Closed cwbsl closed 7 months ago

cwbsl commented 7 months ago

Dependencies

Description of the issue:

I can't download PDF files which have been put into a container field. I get an url like this: https://my-server.com/Streaming_SSL/Additional_1/D7FEB2B23BAC9F3554263627B24B2B53E0B3FB41EECD9C4D6FC57D1E4B68C3BC.pdf?RCType=EmbeddedRCFileProcessor But when I try to visit the URL I get a error 404. I know that it should be possible to get the file with a curl call (Saw that on the msyk library: https://github.com/msyk/FMDataAPI/commit/2f37a3aa947469a96e95b86f08e3ff5729e88e7b) but I can't do that since I can't get the Bearer token with the eloquent library right?

Expected Behavior:

File needs to be downloadable

Steps to reproduce:

  1. Add a container field to FM database (In my case it doesn't matter if files are stored externally or internally)
  2. Try to get the container contents
Smef commented 7 months ago

That format for your container links is correct, and the URLs are generated by FMS itself. This package doesn't do anything to them. Those links are more than a simple download link, though, and actually set a cookie in a browser and then redirect before retrieving the actual file. If this cookie/redirect behavior isn't desired you can disable it through an FMS configuration with a CLI command.

You'll need to make sure that the host url from your FMS is correct and is available to your clients. If you're geting a 404 it could be because your FMS is not returning the correct host address.

This is not related to this package, so you'll need to investigate your FMS configuration.

Smef commented 7 months ago

Also, about getting the file with cURL, yes, you can do that, but it isn't part of the features of this package. You need to make the request, retrieve the cookie, and then make the request a second time to get the actual file.

This might be something we could add in the future as a static method just as a convenience, but you can do it on your own with regular http requests using the Laravel HTTP client, cURL, or any other HTTP request utility.

cwbsl commented 7 months ago

I have set the value to 2 with the CLI command but that also didn't change anything in the behaviour. The url is correct and I'm currently only testing it on my local environment where I have access to the server for sure. My question is how I can get a token with this package that I can use to start a curl call to get the file itself.

Smef commented 7 months ago

The data API does not provide a token for this, and there isn't a token to send. There is no token for this package to provide and no data which you are missing.

You need to actually call that download URL and then set the cookie which the download link replies with, then call the download link again with the cookie attached. Browsers will do this automatically if you provide the download link to your users, but you have to do it manually with cURL.

Alternatively, you can disable this feature and then you won't need the cookies.

Again, though, this security feature would not be giving you a 404. It sounds like your download links are not at the correct host. You would be getting a 401 if you were hitting the security feature requiring the cookie.

cwbsl commented 7 months ago

Oh ok sorry, I didn't know the part about the cookie being set! Thanks a lot for the clarification and sorry for the unnecessary issue opened up.

Smef commented 7 months ago

You're getting a 404, though, so your issue is that your url is incorrect, not that you don't have the cookie being set. This could be an issue with your FMS configuration or some other networking issue, but either way not related to this package. It sounds like you'll need to do some investigation on your routing or FMS.