31#include "moc_qgsalgorithmfileuploader.cpp"
33using namespace Qt::StringLiterals;
37QString QgsFileUploaderAlgorithm::name()
const
39 return u
"fileuploader"_s;
42QString QgsFileUploaderAlgorithm::displayName()
const
44 return tr(
"Upload a file via HTTP(S)" );
47QString QgsFileUploaderAlgorithm::shortDescription()
const
49 return tr(
"Uploads a file to the URL via a HTTP(S) request." );
52QStringList QgsFileUploaderAlgorithm::tags()
const
54 return tr(
"file,uploader,internet,url,upload,post,request,https" ).split(
',' );
57QString QgsFileUploaderAlgorithm::group()
const
59 return tr(
"File tools" );
62QString QgsFileUploaderAlgorithm::groupId()
const
64 return u
"filetools"_s;
67QString QgsFileUploaderAlgorithm::shortHelpString()
const
70 "This algorithm uploads a file to the URL via a HTTP(S) request\n\n"
71 "The optional form name field parameter emulates a filled-in form in which a user has pressed the submit button. This enables uploading of binary files when the URL endpoint requires a form name "
76QgsFileUploaderAlgorithm *QgsFileUploaderAlgorithm::createInstance()
const
78 return new QgsFileUploaderAlgorithm();
81void QgsFileUploaderAlgorithm::initAlgorithm(
const QVariantMap & )
88 auto formNameParam = std::make_unique<QgsProcessingParameterString>( u
"FORM_NAME"_s, tr(
"Form name field" ), QString(),
false,
true );
89 formNameParam->setHelp(
90 QObject::tr(
"The optional form name field parameter emulates a filled-in form in which a user has pressed the submit button. This enables uploading of binary files when url end point requires a form name key" )
92 addParameter( formNameParam.release() );
98 QString url = parameterAsString( parameters, u
"URL"_s, context );
102 const QString filePath = parameterAsFile( parameters, u
"FILE"_s, context );
103 const bool exists = QFileInfo::exists( filePath );
107 const QString formNameKey = parameterAsString( parameters, u
"FORM_NAME"_s, context );
122 if ( errors.size() > 0 )
126 url = uploadUrl.toDisplayString();
127 feedback->
pushInfo( QObject::tr(
"Successfully uploaded file to %1" ).arg( url ) );
133void QgsFileUploaderAlgorithm::sendProgressFeedback()
135 if ( !mSent.isEmpty() && mLastReport != mSent )
138 if ( mTotal.isEmpty() )
139 mFeedback->pushInfo( tr(
"%1 uploaded" ).arg( mSent ) );
141 mFeedback->pushInfo( tr(
"%1 of %2 uploaded" ).arg( mSent, mTotal ) );
145void QgsFileUploaderAlgorithm::receiveProgressFromUploader( qint64 bytesSent, qint64 bytesTotal )
148 if ( bytesTotal > 0 )
150 if ( mTotal.isEmpty() )
153 mFeedback->setProgress( (
static_cast<double>( bytesSent ) /
static_cast<double>( bytesTotal ) ) * 100.0 );
@ File
Parameter is a single file.
bool isCanceled() const
Tells whether the operation has been canceled already.
void canceled()
Internal routines can connect to this signal if they use event loop.
A utility class for uploading files.
void startUpload()
Called to start the upload.
void cancelUpload()
Call to abort the upload and delete this object after the cancellation has been processed.
void uploadError(QStringList errorMessages)
Emitted when an error makes the upload fail.
void uploadCompleted(const QUrl &url)
Emitted when the upload has completed successfully.
void uploadProgress(qint64 bytesSent, qint64 bytesTotal)
Emitted when data are ready to be processed.
static QString representFileSize(qint64 bytes)
Returns the human size from bytes.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
An input file or folder parameter for processing algorithms.
A string parameter for processing algorithms.