如何使用AJAX POST请求在浏览器发送的服务器上捕获上传到C ++程序的文件数据

时间:2019-11-17 13:37:00

标签: c++

我正在浏览器(Firefox 70)中创建音频文件,并使用AJAX将文件发送到服务器(LAMP)C ++ cgi程序。我在C ++中根本没有编写太多代码。客户端...

const audioBlob = new Blob([audioChunks])  //16khz sample rate, 16bit depth
var endpointUrl = "/cgi/receiveFileTest"  // C++ program
//open and send
xhr.open( "POST", endpointUrl )
xhr.setRequestHeader('Content-Type', 'application/octet-stream')
xhr.setRequestHeader('Content-Disposition', 'attachment' )
xhr.send( audioBlob )  //the blob itself

我想处理音频文件。 Apache配置为将请求重定向到此路径的文件     / cgi / ... 至     / usr / local / bin /...

服务器端。 我的测试C ++文件目前有点空!

#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>

#include <cgicc/CgiDefs.h>
#include <cgicc/Cgicc.h>
#include <cgicc/HTTPHTMLHeader.h>
#include <cgicc/HTMLClasses.h>

using namespace std;
using namespace cgicc;

int main () {

    Cgicc formData; //is this nec?

    fstream  audfile;
    audfile.open("[uploadedFile]", ios::in);  //how to address the uploaded file?

    //process audio

    //reply to browser
    cout << "Content-type:text/html\r\n\r\n";
    cout << "audio file received"  << endl;

   return 0;
}

如何将上传的文件读入程序?我打算处理音频

0 个答案:

没有答案