Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !3853

[C++] [Qt5] Add initial version of File upload and download for Qt5 client

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/etherealjoy/qt5_file_download into master Sep 06, 2019
  • Overview 0
  • Commits 3
  • Pipelines 0
  • Changes 70

Created by: etherealjoy

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.
  • Filed the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

  • Add File Upload support for the Qt5 client
  • Add File download support for the Qt5 client
  • Setup file handling for the Qt5 server only for the common part with client

ToDo:

  • Setup file handling for the Qt5 server
  • The HttpFileElement can be extended to pass QIODevice streams instead which includes files, sockets and so on.

Fixes: #3651 #3421 (closed) #3457 (closed)

Note: Not a breaking change for the File handling changes, as it never worked to begin with.

Sample Usage:

#include <QDebug>
#include <QCoreApplication>
#include <QTimer>
#include <OAIDefaultApi.h>

using namespace OpenAPI;

int main(int argc, char *argv[]) {
    QCoreApplication a(argc, argv);
    OAIDefaultApi api;
    api.setHost("http://127.0.0.1:8081");

    OpenAPI::OAIHttpFileElement fileElement;
    fileElement.setMimeType("image/png;charset=UTF-8");
    fileElement.setRequestFileName("FileExt2.png");
    fileElement.setFileName("/home/dev/testapp/ext2.png");
    QString fileId = "fileId";
    qint32 orderId = 555;
    qint32 userId = 777;

    QObject::connect(&api, &OpenAPI::OAIDefaultApi::downLoadFileSignal,
                   [&](OAIHttpFileElement summary)
       {
            qDebug() << "Downloaded the file " << summary.local_filename;
       });

    QObject::connect(&api, &OpenAPI::OAIDefaultApi::upLoadFileSignal,
                   []()
       {
            qDebug() << "Uploaded the file ";
       });

    QObject::connect(&api, &OpenAPI::OAIDefaultApi::upLoadFileWithInfoSignal,
                   []()
       {
            qDebug() << "Uploaded the file with info";
       });
    QTimer::singleShot(0, [&]()
        {
            api.downLoadFile(QString("appsettings.json"));
            api.upLoadFile(fileId, fileElement);
            api.upLoadFileWithInfo(fileId, orderId, userId, fileElement);
        }
    );
    a.exec();
    return 0;
}

sample spec for test

openapi: 3.0.0
servers:
  - url: 'https://api.testapp.com'
info:
  description: Test API for download and upload features.
  version: 1.0.0
  title: testapp.com
paths:
  /downLoadFile/{fileId}:
    get:
      operationId: downLoadFile
      parameters:
        - name: fileId
          in: path
          schema:
            type: string
          required: true
      responses:
        '200':
          description: A picture file
          content:
            image/png:
              schema:
                type: string
                format: binary

  /upLoadFile/{fileId}:
    post:
      operationId: upLoadFile
      parameters:
        - name: fileId
          in: path
          schema:
            type: string
          required: true
      requestBody:
        content:
          image/png:
            schema:
              type: string
              format: binary          
      responses:
        '200':
          description: success
                
  /upLoadFileWithInfo/{fileId}:
    post:
      operationId: upLoadFileWithInfo
      parameters:
        - name: fileId
          in: path
          schema:
            type: string
          required: true
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                orderId:
                  type: integer
                userId:
                  type: integer
                fileName:
                  type: string
                  format: binary          
      responses:
        '200':
          description: success

cc: @stkrwork @MartinDelille @muttleyxd @ravinikam

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/etherealjoy/qt5_file_download