lunnar 0 Posted January 20, 2020 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
FPiette 382 Posted January 20, 2020 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
Angus Robertson 574 Posted January 20, 2020 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
lunnar 0 Posted January 20, 2020 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
Angus Robertson 574 Posted January 20, 2020 Beware ContentType: xls/xls is not commonly supported by browsers, but if it works... Angus Share this post Link to post
Guest Posted January 20, 2020 @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
Angus Robertson 574 Posted January 21, 2020 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