Is it possible to retrieve a file attachment via php script and store it on a webseever? I know how to get the URL of the file but it copies a blank or corrupt file.

  • 0
  • 1
  • Question
  • Updated 3 years ago
  • Answered
When I use php copy function on a file URL in my script, it doesn't return any errors but the file is empty.
Photo of John

John

  • 0 Points

Posted 3 years ago

  • 0
  • 1
Photo of Nathan

Nathan

  • 0 Points
My guess is that the request for the file is not authenticated and so no contents are returned for the copy method to put into the new file.  If your source file doesn't include a 'ticket' or 'username'/'password' parameter in the URL, then that's probably the cause.  This happens because PHP runs server-side and doesn't have access to the cached authentication your browser automatically handles for you when you log in or use the APIs through JavaScript.

You should be able to solve this by making an API_Authenticate call using something like curl and extracting the returned 'ticket' value.  Append the ticket to your source URL like ".../filename.ext?ticket=really_long_ticket_string". 

In a pinch you can also short-circuit the authentication and pass the username and password directly like ".../filename.ext?username=my_user&password=my_password".

By chance, are you using one of the PHP SDKs for Quickbase?  It might have a method to do this for you.
Photo of Nathan

Nathan

  • 0 Points
Where I put "filename.ext?ticket=..." you might have "v0?ticket=..." instead but it works the same.