2017-07-27 4 views
0

mongoose Webサーバーに接続されたWeb GUIからZIPファイルをダウンロードしようとしています。私は単純なアプローチはostreamに応答にはifstreamを渡すことであろう考え出し:mongooseサーバーから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; 
} 

これは役に立ちます。

関連する問題