Revision control
+ /**
+ * Client with 'QtOpenAPICommon' option Test
+ *
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
+ * Do not edit the class manually.
+ */
+
+ #include "QtOAIHttpFileElement.h"
+
+ #include <QtCore/qdebug.h>
+ #include <QtCore/qfile.h>
+ #include <QtCore/qjsondocument.h>
+ #include <QtCore/qjsonobject.h>
+
+ namespace QtOpenAPI {
+
+ void QtOAIHttpFileElement::setMimeType(const QString &mime)
+ {
+ m_mimeType = mime;
+ }
+
+ void QtOAIHttpFileElement::setFileName(const QString &name)
+ {
+ m_localFilename = name;
+ }
+
+ void QtOAIHttpFileElement::setVariableName(const QString &name)
+ {
+ m_variableName = name;
+ }
+
+ void QtOAIHttpFileElement::setRequestFileName(const QString &name)
+ {
+ m_requestFilename = name;
+ }
+
+ bool QtOAIHttpFileElement::isSet() const {
+ return !m_localFilename.isEmpty() || !m_requestFilename.isEmpty();
+ }
+
+ QString QtOAIHttpFileElement::asJson() const
+ {
+ const QByteArray data = asByteArray();
+ return QString::fromUtf8(data);
+ }
+
+ QJsonValue QtOAIHttpFileElement::asJsonValue() const
+ {
+ const QByteArray data = asByteArray();
+ const QJsonObject object = QJsonDocument::fromJson(data).object();
+ return QJsonValue(object);
+ }
+
+ bool QtOAIHttpFileElement::fromStringValue(const QString &instr)
+ {
+ return fromByteArray(instr.toUtf8());
+ }
+
+ bool QtOAIHttpFileElement::fromJsonValue(const QJsonValue &jval)
+ {
+ const QByteArray content = QJsonDocument(jval.toObject()).toJson(QJsonDocument::Compact);
+ return fromByteArray(content);
+ }
+
+ QByteArray QtOAIHttpFileElement::asByteArray() const
+ {
+ QFile file(m_localFilename);
+ QByteArray bArray;
+ if (file.exists() && file.open(QIODevice::ReadOnly)) {
+ bArray = file.readAll();
+ file.close();
+ } else {
+ qDebug() << "Failed to open the file" << m_localFilename;
+ }
+ return bArray;
+ }
+
+ bool QtOAIHttpFileElement::fromByteArray(const QByteArray &bytes)
+ {
+ QFile file(m_localFilename);
+ bool result = file.open(QIODevice::WriteOnly | QIODevice::Truncate);
+ if (result) {
+ const qint64 written = file.write(bytes);
+ file.close();
+ result = (written == bytes.size());
+ if (!result)
+ qDebug() << "Failed to write data to the file" << m_localFilename;
+ } else {
+ qDebug() << "Failed to create the file" << m_localFilename;
+ }
+ return result;
+ }
+
+ bool QtOAIHttpFileElement::saveToFile(const QString &varName, const QString &localFName, const QString &reqFname, const QString &mime, const QByteArray &bytes)
+ {
+ setMimeType(mime);
+ setFileName(localFName);
+ setVariableName(varName);
+ setRequestFileName(reqFname);
+ return fromByteArray(bytes);
+ }
+
+ QByteArray QtOAIHttpFileElement::loadFromFile(const QString &varName, const QString &localFName, const QString &reqFname, const QString &mime)
+ {
+ setMimeType(mime);
+ setFileName(localFName);
+ setVariableName(varName);
+ setRequestFileName(reqFname);
+ return asByteArray();
+ }
+
+ } // namespace QtOpenAPI