2017-07-27 138 views
0

我试图通过连接到猫鼬web服务器的web GUI下载压缩文件。我想通了幼稚的方法是将ifstream的传递到ostream的响应:从猫鼬服务器下载tar.gz

... 
std::stringstream zip_location; 
zip_location << path << "/" << timestamp << ".tar.gz"; 
std::ifstream zip_file(zip_location.str()); 

if(zip_file){ 
    // Enters here fine 
    request.set_response_content_type("application/x-tar-gz"); 
    request.add_response_header(new http_header_fields::cache_control_no_cache); 
    request.out() << zip_file; 
    return true; 
} 
... 

但是,我得到的回应只是一个编码字符串:MHg3ZjRmYTk5Y2RhYjA=,但我想浏览器下载的zip文件。

值得注意的是,我使用的是猫鼬的旧版本,我似乎无法在examples中找到任何解决方案。

回答

0

结果确实在下载文件的request类中实现了一个虚拟函数。您只需传递一个对应于文件路径的字符串即可。

if(zip_file){ 
    request.set_response_content_type("application/x-tar-gz"); 
    request.add_response_header(new http_header_fields::cache_control_no_cache); 
    request.send_file(zip_loc.str()); 
    return true; 
} 

希望这会有所帮助。