Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
esam_tec
Posts: 85
Registered: ‎06-22-2013
My Device: N/A

Web service with photo upload ?

Hello Guys,

 

I have a web service w many parameters(post request), one of the parameters is Image to be uploaded i have used the fallowing code but the response is "Disallowed Key Characters."

 

               QUrl serviceUrl = QUrl(url);
		QByteArray data;
		QUrl params;

		params.addQueryItem("p1", name);
		params.addQueryItem("p2", pass);
		//params.addQueryItem("image", imageFile->readAll());// i cannot deal with the image upload
		data.append(params.toString());
		data.remove(0, 1);

		 QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);

		 QHttpPart textPart;
		 textPart.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("form-data; name=\"text\""));
		 textPart.setBody(data);

		 QHttpPart imagePart;
		 imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg"));
		 imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"image\""));
		 imageFile->open(QIODevice::ReadOnly);
		 imagePart.setBodyDevice(imageFile);
		 imageFile->setParent(multiPart);

		 multiPart->append(textPart);
		 multiPart->append(imagePart);

		QNetworkAccessManager *networkManager = new QNetworkAccessManager(this);
		QNetworkRequest request(serviceUrl);
		request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");

 

Please use plain text.