qt http post 向linux服务器上传文件实现问题 请指导下错误地方!!

唐嘉川 发布于 2016/05/05 17:12
阅读 809
收藏 0
Qt

//上传文件到linux服务器上
void Widget::on_pushButton_2_clicked()
{
QString UrlFilePath = ""; //服务器放置上传文件地址路径
QString filePath = ui->lineEdit_2->text(); //本地将要上传的文件路径
QFileInfo info(filePath);
file = new QFile(filePath);
QString fileName = info.fileName();
if(!file->open(QIODevice::ReadOnly))
{
qDebug() << "file open error";
delete file;
file = NULL;
}
int file_len = file->size();
// QByteArray data = file->readAll();
QDataStream in(file);
m_buf = new char[file_len];
if(in.readRawData(m_buf,file_len)!=file_len){
qWarning("文件读取不完整readRaw");
}
file->close();
delete file;
file = NULL;
UrlFilePath = QString("http://192.168.2.1/images/advertise/%1").arg(fileName);
// UrlFilePath = QString("http://192.168.2.1/images/advertise/");
url.clear();
//准备路径地址
url.setUrl(UrlFilePath);
//准备数据
QByteArray arr = QByteArray(m_buf,file_len);
/*****连接实现*****/
QNetworkRequest request = QNetworkRequest(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
request.setHeader(QNetworkRequest::ContentLengthHeader,QVariant(arr.size()));
reply = manager->post(request,arr); //QNetworkReply reply指针
//上传关联信号
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(upLoadError(QNetworkReply::NetworkError)));

//上传完成后
connect(reply,SIGNAL(finished()),this,SLOT(httpFinished()));
//更新进度条
connect(reply,SIGNAL(uploadProgress(qint64,qint64)),this,SLOT(updateDataReadProgress(qint64 ,qint64)));
ui->progressBar->setValue(0);
//显示进度条
ui->progressBar->show();

}

加载中
0
唐嘉川
上传文件在服务器上的文件夹内不存在,下载实现了,上传的这段代码不知道哪有问题有上传的进度条信号,但是执行完毕后服务器文件夹没有生成要上传的文件,哪位能指导下,谁做过http的下载和上传????
返回顶部
顶部