void imgUploader::uploadImage(QString FileName, QString PhpUploadURL, QString FieldName) { QUrl serviceUrl = QUrl(PhpUploadURL); QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); QNetworkRequest request(serviceUrl); request.setRawHeader("User-Agent", UserAgent.toAscii()); QHttpPart imagePart; imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg")); imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"" + FieldName + "\"; filename=\"" + FileName + "\"")); QFile *file = new QFile(FileName); file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart file->open(QIODevice::ReadOnly); imagePart.setBodyDevice(file); multiPart->append(imagePart); // Call the webservice //QNetworkAccessManager *networkManager = new QNetworkAccessManager(this); currentUpload = manager.post(request, multiPart); connect(currentUpload,SIGNAL(uploadProgress(qint64,qint64)),this, SLOT(onUploadProgress(qint64,qint64))); connect(currentUpload, SIGNAL(finished()),this,SLOT(onUploadFinished())); Uploading = true; //reply->deleteLater(); }
Lvk::FE::UploaderProgressDialog::UploaderProgressDialog(const DAS::ContestData &data, QWidget *parent) : QProgressDialog(tr("Uploading..."), tr("Cancel"), 0, 0, parent), m_uploader(DAS::DataUploaderFactory().createUploader()), m_data(data) { connect(m_uploader, SIGNAL(finished(DAS::ContestDataUploader::Status)), SLOT(onUploadFinished(DAS::ContestDataUploader::Status))); setWindowTitle(APP_NAME); }