Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble returning pdf docs #27

Open
atgreen opened this issue Nov 24, 2020 · 3 comments
Open

Trouble returning pdf docs #27

atgreen opened this issue Nov 24, 2020 · 3 comments

Comments

@atgreen
Copy link

atgreen commented Nov 24, 2020

I'm having trouble understanding how to return non-string content. I'm using hunchentoot, and in this case I want to return PDF documents (which are not static content). Do I need to tell the backend not to expect a string result, or is something like this supposed to work?

(snooze:defroute doc-pdf (:get :application/pdf &key id)
  ;; Load the PDF document ID as an array of octets.
  (read-document *storage-driver* id))
@joaotavora
Copy link
Owner

Hi @atgreen , I'd like to help, as this is a more than reasonable use case, but I'm kind of disconnected from snooze as of late. Can you supply me with a minimal example, or where to find that read-document function? Then it's much easier for me to test.

Do I need to tell the backend not to expect a string result,

In general yes, this is the current Snooze approach to this. Depending on the backend you've chosen, its practices are likely still viable inside the route's dynamic context, you can probably tell it that the return value is a sequence of octets. For example, in Hunchentoot, you can also do other stuff like setting headers in replies with (setf (hunchentoot:header-out* "Foo:") "bar"). So you can probably set some special variable to indicate that what youre about to return is octets. Ideally, you would also be able to return a stream object and the backend would deal with that.

The adaptation between snooze and the backend you've chosen is probably also a point you can tweak. Just dig around in the code.

@strawhatguy
Copy link

I ran into this too recently (although with images I had byte vectors of), if you're still interested @atgreen I made a PR from my fork: #32

@strawhatguy
Copy link

ah nevermind, I missed you were using hunchentoot, my PR is for clack/woo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants