Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-72791

QHTTPMultiPart no longer abides by Google's new strict multipart validation process

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.11
    • Network: HTTP
    • None
    • All

    Description

      Recently my youtube uploading code stopped working, which relied on a basic multipart

      void QNetworkTools::uploadYoutubeVideo(QFile &file, const QString &title, QString description, const QStringList &tags)
      {
      	/* Create Request */
      	QNetworkRequest request;
      	{
      // There may be some useless parameters in here. They were only added as I was 
      // trying to figure out if I could use them to make the upload work
      		setUri("https://www.googleapis.com/upload/youtube/v3/videos");
      		addUrlParameter("part", "snippet,status");
      		addUrlParameter("client_id",    OAuth2.client_id());
      		addUrlParameter("redirect_uri", OAuth2.redirect_uri());
      		addUrlParameter("scope",        OAuth2.scope());
      		addUrlParameter("notifySubscribers", "False");
      		addUrlParameter("onBehalfOfContentOwner", "");
      		addUrlParameter("onBehalfOfContentOwnerChannel", "");
      
      		request.setUrl(uri());
      		request.setRawHeader("Authorization", "Bearer " + OAuth2.access_token().toUtf8());
      	}
      
      	/* Video Settings */
      	QHttpMultiPart* multiPart = new QHttpMultiPart(QHttpMultiPart::MixedType);
      	QString body;
      	{
      		QHttpPart jsonPart;
      		jsonPart.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json"));
      		body = QString(R"(
      			       "kind": "youtube#video",
      			       "snippet":
      			       {
      				       "title": "%1",
      				       "description": "%2",
      				       "tags": ["%3"],
      				       "categoryId": "27"
      			       },
      			       "status":
      			       {
      				       "privacyStatus": "public",
      				       "license": "creativeCommon"
      			       },
      			       "notifySubscribers": "False"
      			       )").arg(title, description.remove("\""), tags.join("\",\"")).remove("	");
      		jsonPart.setBody(body.toUtf8());
      		multiPart->append(jsonPart);
      	}
      
      	/* Video File */
      	QHttpPart videoPart;
      	{
      		if (file.open(QIODevice::ReadOnly)) { videoPart.setBodyDevice(&file); }
      		videoPart.setHeader(QNetworkRequest::ContentTypeHeader,        QVariant("video/*"));
      		videoPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("Slug"));
      		multiPart->append(videoPart);
      	}
      	QNetworkReply *reply = m_NetworkAccessManager.post(request, multiPart);
      
      	QEventLoop waitForUpload;
      	connect(reply, &QNetworkReply::finished, &waitForUpload, &QEventLoop::quit);
      	waitForUpload.exec();
      	disconnect(reply, &QNetworkReply::finished, &waitForUpload, &QEventLoop::quit);
      }
      

      After much confusion, I stumbled across two posts:
      +https://stackoverflow.com/questions/52844182/getting-malformed-multipart-body-when-trying-to-upload-video-to-youtube
      +
      This one leads you to believe that google may have disabled multipart uploading. However upon further searching,
      https://github.com/Elringus/UnityGoogleDrive/issues/30#issuecomment-436971836
      states the following:
      _Looks like Google has made validation of the multipart bodies more strict. I've had to manually compose the body, preserving all the new lines and spaces, before it finally accepted the request. Multipart uploads in the latest release should work fine now: https://github.com/Elringus/UnityGoogleDrive/releases/tag/v0.22-alpha
      _

      This looks like a bug unfortunately introduced by google.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              cnn Qt Core & Network
              akiva Akiva Avraham
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes