Send multiple files in a response with Cherrypy.

32 views
Skip to first unread message

Jose Henrique S Junior

unread,
Nov 3, 2020, 3:20:30 AM11/3/20
to cherrypy-users
Ok guys, I have a server, written in Cherrypy, and the code for receiving files and saving them to disk is ready.

Now I am trying to respond to a GET query, with a list of responses, and some files attached to each of those responses. I've been looking on the internet for it, but I must not be using the right words on my search, because I haven't got any hits.

Any ideas on where to look or how to proceed?

David Allouche

unread,
Nov 3, 2020, 4:37:42 AM11/3/20
to cherrypy-users
Hello,

You should start with an entry level book on web programming. Maybe this one: https://www.oreilly.com/library/view/http-the-definitive/1565925092/

More specifically, what you say you are trying to do makes no sense in the HTTP protocol, where one request produces one response.

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cherrypy-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cherrypy-users/0d28bd12-ce86-43ea-a29d-60237c5095a6n%40googlegroups.com.

Sviatoslav Sydorenko

unread,
Nov 3, 2020, 9:48:05 AM11/3/20
to cherryp...@googlegroups.com
Hey Jose,

> > On 3 Nov 2020, at 01:03, 'Jose Henrique S Junior' via cherrypy-users <cherryp...@googlegroups.com> wrote:
> > Now I am trying to respond to a GET query, with a list of responses, and some files attached
> > to each of those responses. I've been looking on the internet for it, but I must not be using the
> > right words on my search, because I haven't got any hits.
> >
вт, 3 лист. 2020 о 10:37 David Allouche <da...@allouche.net> пише:
> You should start with an entry level book on web programming. Maybe this one: https://www.oreilly.com/library/view/http-the-definitive/1565925092/
>
> More specifically, what you say you are trying to do makes no sense in the HTTP protocol,
> where one request produces one response.
>

as David wrote, it's important to understand how HTTP works,
especially given that CherryPy is
a microframework where you're working with low-level stuff more than
in high-level frameworks.

It sounds like you want to implement a list operation typical to CRUD.
The way it's usually solved
is implementing some sort of and API that responds with structured
data like JSON (see
also REST). When the client sends an API request over HTTP, it gets a
list of pointers to files
(often accompanied with some extra metadata like names/dates etc.)
Then, the client parses that list, extracts the URLs to files, and
issues a series of separate
subsequent HTTP requests in order to download those files.

Of course, it's technically possible to embed files into that first
HTTP response but it's not really
common. You could pack different chunks of data using the multipart
MIME type or come up
with your own serialization for embedding the data. Although, be
prepared to implement proper
parsing on the client.

P.S. It'll still be one HTTP response to one HTTP request. Be aware
that CherryPy supports
HTTP/1.1 and not HTTP/2. So when you'll learn about HTTP, make sure
you understand how
this version works.


--
Cheers,
Sviatoslav.

---
https://useplaintext.email/
() ascii ribbon campaign - against html e-mail
/\ www.asciiribbon.org - against proprietary attachments
---

Michiel Overtoom

unread,
Nov 4, 2020, 3:16:17 AM11/4/20
to cherryp...@googlegroups.com
Hi,

> the code for receiving files and saving them to disk is ready.

I once made a webapp which had to let a visitor download multiple files in one click. I realized this by putting them in a ZIP file, and serve that as a response. AFAIK it's not possible to have multiple files served to the browser with a single request.

Greetings,

--
"You can't actually make computers run faster, you can only make them do less." - RiderOfGiraffes

ingo janssen

unread,
Nov 4, 2020, 6:37:13 AM11/4/20
to cherryp...@googlegroups.com
One could use SSE to tell / trigger the client to download what from
where. Kind of one request multiple replies.

I'd prefer a Zip.
Reply all
Reply to author
Forward
0 new messages