#1 2013-03-02 15:23:15

colbert
Member
Registered: 2013-03-02
Posts: 38
Website

Best way to send files

Hi,

Gentlemen, what would be the most appropriate way (faster) to send a File from the server to the Client?
For Now I'm using the REST  approach with the ORM and a SQlite database.

God bless us all.

Thank you

Offline

#2 2013-03-04 19:38:57

Junior/RO
Member
Registered: 2011-05-13
Posts: 210

Re: Best way to send files

I need this too. Sometimes need to send big pictures (6MB+) and don't know what is the better approach.

How to get feedback to show a gauge, for example?

Last edited by Junior/RO (2013-03-04 20:26:15)

Offline

#3 2013-03-05 07:24:16

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

Re: Best way to send files

If the picture is a file, you can use a special kind of content type response, as defined in SynCrtSock unit.

const
  /// used by THttpApiServer.Request for http.sys to send a static file
  // - the OutCustomHeader should contain the proper 'Content-type: ....'
  // corresponding to the file (e.g. by calling GetMimeContentType() function
  // from SynCommons supplyings the file name)
  HTTP_RESP_STATICFILE = '!STATICFILE';

Note that it will work only with THttpApiServer kind of server (i.e. using high performance http.sys API).
But whole file access and sending will occur in background, at the kernel level, so with best performance.

It is used by sample "09 - HttpApi web server". See HttpApiServer.dpr

But this does not handle chunking process, so I guess a "gauge" may not work as expected for AJAX.
For non AJAX client process, it will depend on your client class.

Offline

#4 2013-03-05 12:02:09

colbert
Member
Registered: 2013-03-02
Posts: 38
Website

Re: Best way to send files

In my case, I don't know if is the best for me because I am using the class as a TSQLHttpServer and my client is in delphi.

Should I use interfaced based services? How can I get the progress of the file transfer?

Offline

#5 2013-03-05 12:24:31

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

Re: Best way to send files

TSQLHttpServer  can use HTTP_RESP_STATICFILE kind of content.
It will let the server side be much scalable, if your purpose is exactly to serve some file content.

In all cases, all RESTful process relies on memory, so even interface-based services is not meant to server GB of data.
Unless you switch to 64 bit version of the compiler.

The Delphi HTTP client classes do not have a progress callback yet.
It may be possible to add it at TWinHttpAPI class level, i.e. for WinINet and WinHTTP APIs. You can add a feature request as a ticket in http://synopse.info/fossil/reportlist
For direct socket client, it would need more code refactoring.

Offline

#6 2013-09-11 13:50:14

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: Best way to send files

I want to discuss this http://synopse.info/fossil/info/ce1141092e  ticket.

I agree with you about  using FindIniNameValue()  and work with InHead. Everything is OK here.

But what should I do to send static file with custom content type? Seams I must add CONTENT-TYPE twice into OutHeader?

   Ctxt.Call.OutHeader := HEADER_CONTENT_TYPE + HTTP_RESP_STATICFILE + #13#10 + HEADER_CONTENT_TYPE + getMyCustomContentType();

I'm right?

Offline

#7 2013-09-11 14:13:49

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

Re: Best way to send files

Sounds like the expected way.

Offline

#8 2013-09-11 16:18:38

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: Best way to send files

Yes, I rewrite my code in this manner - everything work good and now I'm compatible with main mORMot branch smile
Just one remark - when I send static files in this manner I get incorrect statistics:

TSQLRestServer.URI()
.....
  inc(fStats.fOutcomingBytes,length(Call.OutHead)+length(Call.OutBody)+16);

we actually increase out bytes by fileName length
As for me is good to add fStats.fileTransfered counter and count number of files we send (calculating real file length is slow?)

Offline

#9 2013-09-11 17:46:29

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

Re: Best way to send files

mpv wrote:

As for me is good to add fStats.fileTransfered counter and count number of files we send (calculating real file length is slow?)

Good idea!

Please create a ticket for this small enhancement, so that we won't forget it.

Offline

#10 2013-09-12 08:01:37

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: Best way to send files

Offline

Board footer

Powered by FluxBB