Jump to content
lunnar

filename for download file THttpServer

Recommended Posts

hi. I need to send download file. I use

ContentType:='xls/xls';
Cli.AnswerStream(Dummy,'',ContentType,'');

where I need to write Filename? 

If I try 

Cli.AnswerStream(Dummy,'',ContentType,'Content-Disposition: attachment; filename="'+ExtractFileName(Fullpath)+'"');

I get file with 0 byte

Share this post


Link to post

Please clarify your question: in my mind,"send" and "download" are not compatible. It is either "receive" and "download" or "send" and "upload".

Have a look at various demos delivered with ICS distribution.

 

Share this post


Link to post

Generally, the 'filename' is that of the page accessed with the GET request and is not returned in the response header.   Again generally you should use the FilenameToContentType function to get the content type, which will return 'application/octet-stream' for an XLS file, which will cause the browser to bring up a dialogue box asking what to do with the file.  If you want to display the file, there are Microsoft special headers to do so.  Keep it simple until it works.

 

Angus

 

Share this post


Link to post

AnswerStream is a send but for browser it's a download file. 

But it's easy:

	var link = document.createElement('a');
	link.setAttribute('href','xls/'+ID+'.xls');
	link.setAttribute('download',ID+'.xls');
	onload=link.click();	

now, all good, thx

Share this post


Link to post
Guest

@lunnar Angus is right ContentType is important and you are not using standard one, i recommend to stick to the standard mime types, i faced this few times with browsers, this is real problem with email attachments,

Sources :

https://stackoverflow.com/questions/974079/setting-mime-type-for-excel-document

https://docs.microsoft.com/en-us/archive/blogs/vsofficedeveloper/office-2007-file-format-mime-types-for-http-content-streaming-2

 

Share this post


Link to post

ICS has a TMimeTypesList component that will read MIME types from the Windows registry, a supplied file mime.types or an internal list, application/vnd.ms-excel is common.  This component is used by TSslHttpServer for files it opens.

 

Angus

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×