void HttpWindow::uploadFile()
{
tr("OpenFile"),
openFilesPath,
tr("All Files (*);;Text Files (*.txt)"));
if (!fileName.isEmpty())
openFilesPath = fileName;
QString fileName1
= path.
fileName();
userfile
= new QFile(openFilesPath
);
{
tr("Unable to open the file %1: %2.")
.arg(openFilesPath).arg(userfile->errorString()));
}
header.setValue("Host", "foliant");
header.setValue("Content-type", "multipart/form-data, boundary=AaB03x");
header.setValue("Cache-Control", "no-cache");
header.setValue("Accept","*/*");
bytes.append("--AaB03x\r\n");
bytes.append("content-disposition: ");
bytes.append("form-data; name=\"agency\"\r\n");
bytes.append("\r\n");
bytes.append("0\r\n");
bytes.append("--AaB03x\r\n");
bytes.append("content-disposition: ");
bytes.append("form-data; name=\"userfile\"; filename=\"" + byt+ "\"\r\n");
bytes.append("Content-Transfer-Encoding: binary\r\n");
bytes.append("\r\n");
bytes.append(userfile->readAll());
userfile->close(); // the file is opened earlier in the code
bytes.append("\r\n");
bytes.append("--AaB03x--");
int contentLength = bytes.length();
header.setContentLength(contentLength);
http->setHost("foliant");
httpRequestAborted = false;
httpGetId = http->request(header, bytes);
}
void HttpWindow::uploadFile()
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("OpenFile"),
openFilesPath,
tr("All Files (*);;Text Files (*.txt)"));
if (!fileName.isEmpty())
openFilesPath = fileName;
QFileInfo path(openFilesPath);
QString fileName1 = path.fileName();
userfile = new QFile(openFilesPath);
if ( !userfile->open(QIODevice::ReadOnly) )
{
QMessageBox::information(this, tr("HTTP"),
tr("Unable to open the file %1: %2.")
.arg(openFilesPath).arg(userfile->errorString()));
}
QHttpRequestHeader header("POST", "/upload.php", 1, 1);
header.setValue("Host", "foliant");
header.setValue("Content-type", "multipart/form-data, boundary=AaB03x");
header.setValue("Cache-Control", "no-cache");
header.setValue("Accept","*/*");
QByteArray byt(openFilesPath.toUtf8());
QByteArray bytes;
bytes.append("--AaB03x\r\n");
bytes.append("content-disposition: ");
bytes.append("form-data; name=\"agency\"\r\n");
bytes.append("\r\n");
bytes.append("0\r\n");
bytes.append("--AaB03x\r\n");
bytes.append("content-disposition: ");
bytes.append("form-data; name=\"userfile\"; filename=\"" + byt+ "\"\r\n");
bytes.append("Content-Transfer-Encoding: binary\r\n");
bytes.append("\r\n");
bytes.append(userfile->readAll());
userfile->close(); // the file is opened earlier in the code
bytes.append("\r\n");
bytes.append("--AaB03x--");
int contentLength = bytes.length();
header.setContentLength(contentLength);
http->setHost("foliant");
httpRequestAborted = false;
httpGetId = http->request(header, bytes);
}
To copy to clipboard, switch view to plain text mode
Bookmarks