2017-07-27 139 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; 
} 

希望這會有所幫助。