send just the filename in Content-Disposition
Thanks go to: @hagai-shatz
This commit is contained in:
parent
a52873b451
commit
5ee66e1842
|
@ -347,9 +347,11 @@ void AsyncFileResponse::_setContentType(String path){
|
|||
}
|
||||
|
||||
AsyncFileResponse::AsyncFileResponse(FS &fs, String path, String contentType, bool download){
|
||||
char buf[64];
|
||||
_code = 200;
|
||||
_path = path;
|
||||
int filenameStart = path.lastIndexOf('/') + 1;
|
||||
char buf[26+path.length()-filenameStart];
|
||||
char* filename = (char*)path.c_str() + filenameStart;
|
||||
|
||||
if(!download && !fs.exists(_path) && fs.exists(_path+".gz")){
|
||||
_path = _path+".gz";
|
||||
|
@ -363,10 +365,10 @@ AsyncFileResponse::AsyncFileResponse(FS &fs, String path, String contentType, bo
|
|||
|
||||
if(download) {
|
||||
// set filename and force download
|
||||
snprintf(buf, sizeof (buf), "attachment; filename='%s'", path.c_str());
|
||||
snprintf(buf, sizeof (buf), "attachment; filename='%s'", filename);
|
||||
} else {
|
||||
// set filename and force rendering
|
||||
snprintf(buf, sizeof (buf), "inline; filename='%s'", path.c_str());
|
||||
snprintf(buf, sizeof (buf), "inline; filename='%s'", filename);
|
||||
}
|
||||
addHeader("Content-Disposition", buf);
|
||||
|
||||
|
@ -469,4 +471,3 @@ size_t AsyncResponseStream::write(const uint8_t *data, size_t len){
|
|||
size_t AsyncResponseStream::write(uint8_t data){
|
||||
return write(&data, 1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue