#1 2017-09-28 13:03:13

jaclas
Member
Registered: 2014-09-12
Posts: 215

Download file from mORMot by click link in browser

I need to provide downloads files through the browser, by click and download. The website is based on JS and retrieves from the interface based service (mORMot) links to files.
The files are on the disk and I would like them to be accessed by the mORMot server for download. Does mORMot support regular download by link?
Or how else to do it?

Offline

#2 2017-09-28 13:12:35

sevo
Member
Registered: 2015-11-10
Posts: 27

Re: Download file from mORMot by click link in browser

https://synopse.info/files/html/Synopse … ml#TITL_95
Edit: Chapter "Returning file content" in the documentation.

Last edited by sevo (2017-09-28 13:15:59)

Offline

#3 2017-09-28 13:23:24

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Download file from mORMot by click link in browser

Framework's HTTP server is able to handle returning a file as response to a method-based service.

The service is interface based hmm
Can interface based and method based service be registered simultaneously in one http server?

Offline

#4 2017-09-28 15:26:01

sevo
Member
Registered: 2015-11-10
Posts: 27

Re: Download file from mORMot by click link in browser

Yes, you can generate links which point to a method based service.

Offline

#5 2017-09-29 07:23:36

Chaa
Member
Registered: 2011-03-26
Posts: 249

Re: Download file from mORMot by click link in browser

In interface based service you can use TServiceCustomAnswer for interface function result type, see
https://synopse.info/files/html/Synopse … l#TITL_154

Offline

#6 2017-09-29 09:53:41

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Download file from mORMot by click link in browser

Which method is better? Which method does the server load less?

Offline

#7 2017-09-29 11:04:48

Chaa
Member
Registered: 2011-03-26
Posts: 249

Re: Download file from mORMot by click link in browser

If you use http.sys server, then Ctxt.ReturnFile cause less overhead - it can send file contents in kernel-mode without memory copiyng.

Offline

#8 2017-09-29 14:05:18

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Download file from mORMot by click link in browser

Thx, I will try ReturnFile!

Offline

#9 2017-10-30 14:30:45

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Download file from mORMot by click link in browser

One more question. When I use parameter of TServiceCustomAnswer type in interface-based service then data transmitted will base64 encoded or binary?

Offline

#10 2017-10-30 16:18:32

Chaa
Member
Registered: 2011-03-26
Posts: 249

Re: Download file from mORMot by click link in browser

You have full control on response headers and content.
Exactly what you put in TServiceCustomAnswer.Content will be sent to client, and by the HTTP server no encoding will be performed.

Offline

#11 2017-10-30 18:49:15

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Download file from mORMot by click link in browser

I captured the request (via OnRequest event) and the .Content data was encoded in base64 :-(

Offline

#12 2017-10-30 20:23:10

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Download file from mORMot by click link in browser

The TServiceCustomAnswer is for the answer, not the request - as its name states. wink

There is currently no way of pushing raw content to an interface-based service.

Use a method-based service, for such kind of file upload, as stated upstairs on this post.

Offline

#13 2017-10-30 21:15:51

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Download file from mORMot by click link in browser

Ok, I understand... but... would it be possible to add the ability to send data in raw mode? no encoding, binary? of course in interface-based service :-)

This would be very useful in some cases!
Please, think of it...

Offline

Board footer

Powered by FluxBB