diff sv/main/EasaierSessionManager.cpp @ 249:56b913f1fd05

Fix bugs in post data: - boundary - file upload
author lbarthelemy
date Tue, 10 Jun 2008 07:59:55 +0000
parents 37b7f4ec5a17
children c12986afc03c
line wrap: on
line diff
--- a/sv/main/EasaierSessionManager.cpp	Mon Jun 09 12:41:10 2008 +0000
+++ b/sv/main/EasaierSessionManager.cpp	Tue Jun 10 07:59:55 2008 +0000
@@ -223,7 +223,7 @@
 	QHttpRequestHeader header("POST", m_httpClient->getServletName());
 	header.setValue("Host", m_httpClient->getHost());
 	header.setValue("Port", QString::number(m_httpClient->getHostPort()));
-    header.setContentType("multipart/form-data, boundary=7d44e178b0434");
+    header.setContentType("multipart/form-data; boundary=7d44e178b0434");
     header.setValue("Cache-Control", "no-cache");    
 	header.setValue("Accept","*/*"); 
     header.setContentLength(payload.length());
@@ -511,13 +511,13 @@
 	QString boundary="7d44e178b0434";
 	QString endline="\r\n";
 	QString start_delim="--"+boundary+endline;
-	QString cont_disp_str="Content-Disposition: form-data; ";
+	QString cont_disp_str="Content-Disposition: form-data;";
 
 	QByteArray *payload = new QByteArray();
 	QDataStream data_stream(payload, QFile::WriteOnly | QFile::Unbuffered);
 	/////////
 
-	QString param = start_delim + cont_disp_str + "name=" + "\"theme\""+endline+endline+themeName+endline;
+	QString param = start_delim + cont_disp_str + "name=" + "\"theme\"" + endline+endline+themeName+endline;
 	data_stream.writeRawData(param.toStdString().c_str(),param.toStdString().length());
 
 	if(themeModel!=0){
@@ -526,6 +526,7 @@
 		for(int i=0; i< ((int) propertyList.size());i++){
 			if (themeModel->getPropertyType(propertyList[i]) == PropertyContainer::FileProperty)
 			{
+				// We are here dealing with a filePath
 				postFilePath = themeModel->getPropertyValue(propertyList[i]);
 				if(postFilePath!=""){
 					QString only_filename = postFilePath.section( '/', -1 );
@@ -533,18 +534,18 @@
 					data_stream.writeRawData(param.toStdString().c_str(),param.toStdString().length());
 					
 					QFile file(postFilePath);
-					long int i=0;
-					char *s=new char[file.size()+2];
-					
-					while (!file.atEnd()) {
-						QByteArray line = file.readLine();
-						data_stream.writeRawData(line.data(),line.length());
+					if (file.open( QFile::ReadOnly )) {
+						while (!file.atEnd()) {
+							QByteArray line = file.readLine();
+							data_stream.writeRawData(line.data(),line.length());
+						}
+						file.close();
 					}
-					file.close();
 				}
 			}
 			else{
-				QString param = start_delim + cont_disp_str + "name=" + "\""+propertyList[i]+"\""+endline+endline+themeModel->getPropertyValue(propertyList[i])+endline;
+				// Normal parameter
+				QString param = start_delim + cont_disp_str + "name=" + "\"" + propertyList[i]+ "\"" + endline+endline+themeModel->getPropertyValue(propertyList[i])+endline;
 				data_stream.writeRawData(param.toStdString().c_str(),param.toStdString().length());
 			}
 		}