I am working in QT5 and am struggling with a multipart upload. My script is as much as possible:
quarrel test url ("http: //localhost/upload/test.php"); QNetworkRequest request (testUrl); QHttpMultiPart * Multipart = New QHttpMultiPart (QHttpMultiPart :: FormDataType); Qustring preview_path = "C: / preview.jpg"; QHttpPart PreviewPathpath; PreviewPathPart.setHeader (QNetworkRequest :: ContentDispositionHeader, QVariant ("form-data; name = \" preview_path \ "")); PreviewPathPart.setBody (preview_path.toLatin1 ()); QHttpPart PreviewFileport; PreviewFilePart.setHeader (QNetworkRequest :: ContentTypeHeader, QVariant ("Image / JPEG")); PreviewFilePart.setHeader (QNetworkRequest :: ContentDispositionHeader, QVariant ("form-data; name = \" preview_file \ "")); QFile * file = new QFile (preview_path); If (! File-> exists ()) {emit error (tr ("upload error. File does not exist:") + preview_path); Return; } File-> Open (QIODevice :: ReadOnly); PreviewFilePart.setBodyDevice (file); File & gt; SetParent (Multipurpose); // We can not delete the file anymore, so it is called multipart multipart-> Delete with attachment (preview page text); MultiPart- & gt; Attached (previewFilePart); Answer = Network Manager- & gt; Post (request, multipart); MultiPart- & gt; SetParent (responses); // Removing Multipart with North Connect (Answer, Signal (Finish), Slot (Upload () ()); Connect (Answer, Signal (Error (Q Networkwork: Network Error), This Slot (Uploaded in progress (qint64, qint64));); Upload error (Q Networkwork: Network Error)); Connect (Answer, Signal (Upload Progress (qint64, qint64)), this, slot (upload progress (qint64, qint64)); Then my upload () slot prints the answer only:
QString data = (QString) Answer-> ReadAll (); QDebug () I have the upload script as simple as it is running in XPP / upper / 2.2.21 and PHP 5.3.8. My upload_max_files and post_max_isms are 1000m. < Pre echo "preview_path:". (Isset ($ _ POST ['preview_path']) $ $ _POST ['preview_path']: "not set"). "\ R \ n"; echo "preview_file exists "True": "wrong"). "\ R \ n"; echo '$ _FILES:'; print_r ($ _ files); echo "preview_file (" Isset ($ _ POST ['preview_file'])? Content: "$ _POST ['preview_file']; My progress slot shows that almost the exact number of bytes Uploading
but output shows:
preview_path: C: /preview.jpg preview_file exists: true $ _FILES: array () preview_file Content: ?? ?? It seems that bytes are being presented as $ $ _POST variables instead of $$ FILE, as they should be? There is no error in Apache log. How can this debug it?
Resolve!
Thanks for the prompt - I've added 'filename' in the content nature for QHttpPart and uploads it as expected now I thought the filename was optional but it works in this case . Hope this helps someone else!
QString preview_name = "preview.jpg"; QHttpPart PreviewFileport; PreviewFilePart.setHeader (QNetworkRequest :: ContentTypeHeader, QVariant ("Image / JPEG")); PreviewFilePart.setHeader (QNetworkRequest :: ContentDispositionHeader, QVariant ("form-data; name = \" preview_file \ ", file name = \" "+ preview_name +" \ "")));
No comments:
Post a Comment