Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 728151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:38:55+00:00 2026-05-14T06:38:55+00:00

I’m looking for a basic code samples of how to upload files to server

  • 0

I’m looking for a basic code samples of how to upload files to server with HTTP POST method on Qt.

My task: I have simple Qt program and I need to select any image file from the local host and upload it to the server. The selection part and GUI is simple and I have already done it, but with POST uploading I’m confused. In addition I have to say, that there is no authorization to upload file.

If someone already looking this topic?

PS: the reason why I’m asking and not coding my self is time, I need to get this method quick.

Thank you, all success solutions from my side will be posted here for others.

ADDED: Here is my code, that doesn’t work yet. Upload site located here.

void    CDialog::on_uploadButton_clicked() {

    QFileInfo fileInfo(absPathLineEdit->text());

    if (!fileInfo.exists()) {
        QMessageBox::information(this, 
            tr("Information"), 
            tr("File doesn't exists! Please, select another image."));
        return;
    }

    file = new QFile(fileInfo.filePath());
    if (!file->open(QIODevice::ReadOnly)) {
        QMessageBox::information(this,
            tr("Information"),
            tr("Unable to open file for reading!"));
        return;
    }

    QString host = "http://data.cod.ru";

    QUrl url(host);

    QHttp::ConnectionMode mode = QHttp::ConnectionModeHttp;
    http->setHost(url.host(), mode, (url.port() == -1) ? 80 : url.port());

    QHttpRequestHeader header("POST", "/", 1, 1);
    header.setValue("Host", "data.cod.ru");
    header.setValue("Content-type", "multipart/form-data, boundary=AaB03x");
    header.setValue("Cache-Control", "no-cache");
    header.setValue("Accept", "*/*");

    QByteArray bytes(fileInfo.filePath().toUtf8());
    QByteArray totalBytes;
    totalBytes.append("--AaB03x\r\n");
    totalBytes.append("Content-Disposition: form-data; name=\"email\"\r\n");
    totalBytes.append("\r\n");
    totalBytes.append("billgates@microsoft.com\r\n");
    totalBytes.append("--AaB03x\r\n");
    totalBytes.append("Content-Disposition: form-data; name=\"photo\"; filename=\"" + bytes+ "\"\r\n");
    totalBytes.append("Content-Transfer-Encoding: binary\r\n\r\n");
    totalBytes.append(file->readAll());
    totalBytes.append("\r\n");
    totalBytes.append("--AaB03x--");

    header.setContentLength(totalBytes.length());

    httpRequestAborted = false;
    httpGetId = http->request(header, totalBytes);

    file->close();
}

and read answer function below:

void    CDialog::httpRequestFinished(int requestId, bool error) {

    if (requestId != httpGetId)
        return;

    if (httpRequestAborted) {
        if (file) {
            file->close();
//          file->remove();
//          delete file;
            file = 0;
        }
        return;
    }

    if (requestId != httpGetId)
        return;

    file->close();

    if (error) {
//      file->remove();
        QMessageBox::information(this, tr("HTTP"),
            tr("Download failed: %1.")
            .arg(http->errorString()));
    } else {
        QByteArray data = http->readAll();
        QFile *dataFile = new QFile("answer.txt");
        dataFile->open(QIODevice::WriteOnly | QIODevice::Text);
        dataFile->write(data);
        dataFile->flush();
        dataFile->close();
    }

//  delete file;
    file = 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:38:55+00:00Added an answer on May 14, 2026 at 6:38 am

    Also, I found today nice code: link text

    It’s uploader/downloader app based on Qt4, with full set of POST headers managed by QNetworkAccessManager inside, so for beginners it will be very helpful.

    Owner:
    stiff.ru

    Committer:
    hoxnox

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.