Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Sep 17, 2019

Conversation

etherealjoy
Copy link
Contributor

@etherealjoy etherealjoy commented Sep 6, 2019

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
#3457

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

Copy link
Contributor

@muttleyxd muttleyxd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two things

@wing328 wing328 added this to the 4.1.3 milestone Sep 14, 2019
@wing328
Copy link
Member

wing328 commented Sep 16, 2019

If no further feedback, I'll merge tomorrow (Tue)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants