Unable to upload file using "upload_file" method

Mehr
4 Monate 3 Wochen her #180963 von nmanthena
Yeah @DenisChenu
Any solution for file uploading.

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
4 Monate 3 Wochen her #180965 von nmanthena
Yes with string its working but file was not uploading

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
4 Monate 3 Wochen her #180971 von nmanthena
Thanks lot @DenisChenu,

With the string its working.
Folgende Benutzer bedankten sich: DenisChenu

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
4 Monate 3 Wochen her #181004 von DenisChenu

nmanthena schrieb: Thanks lot @DenisChenu,

With the string its working.

OK,

It can be great if you can put a sample code somewhere :).

Or maybe improve autodoc ?

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand .
An error happen ? Before make a new topic : remind the Debug mode .

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
4 Monate 3 Wochen her #181019 von nmanthena
This is the way I am doing the file upload passing file data as string, after using upload_file method.
{
"method": "add_response",
"params": [
"iNlt2f8MDedFQyfAarfU0hcpNCx65FTf",
272826,
{
"272826X1X1": "[{ \"title\":\"google imagesss\",\"comment\":\"png filessss \",\"name\":\"futmp_scf3thzcy4ew8ww_png.png\",\"filename\":\"futmp_scf3thzcy4ew8ww_png\",\"size\":\"13.506\"}]"
}
],
"id": 1
}
Folgende Benutzer bedankten sich: DenisChenu

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
4 Monate 3 Wochen her #181029 von tpartner
For those interested, here is a complete PHP example of uploading a file and then (thanks to input from DenisChenu) creating a new survey response with that file:

<?php
 
	require_once 'jsonRPCClient.php';
 
	define( 'LS_BASEURL', 'http://pathTo/limeSurvey');  
	define( 'LS_USER', 'admin' );
	define( 'LS_PASSWORD', 'password' );
 
	$iSurveyID = 885886; // Survey ID
	$g1ID = 330; // Group ID
	$q1ID = 5152; // Question ID
 
	$sFieldName = $iSurveyID.'X'.$g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WpF8Xn7QbyLTyBTb17ZV7zGb99UAzNldjaD5dKewmAWrnOUKYTygon8fhzco1snv2MoP9RpvPl1+n28BOmUVjuMaZduueYb2pAL/VwiWFs1pEvkbtgzd1U/dt9UPpdcV3Ia65/qJrG5UOZm9sm0i08+U29e2Ve8xm/fVAMzZXY2g+XSnsJgPC84W1jVLMNVYb2pqjnfKxxMurR3+Oiv8ARjDJXa1xMvbb/SthSFaiK7u1stM6Ygi1jP8AIXa4p9uCqvN7L86MNZ4hof5/6MbscOLzMu7a/gnRtUym3r2yr3mM376oBmbK7G0Hy6U9hMBurtFXVpUy4nXpRCgUuBrZwtKtCFBQORiADK+abRRMLcYuOdabUeozumiE/YRj2Qsxy8kOrRubJa8lNtPztXn6ghtQUZdW6bbVjXCtlGcd+sR6cJnmZJGJttDbaW20hDaAEoQkYAA4ACM1VlAKbevbKveYzfvqgMGbuuthlthitT7TLSQhppEy8lKUpGAlICsAAcBAZ9Nby8eqPq3/AJQE6a3l49UfVv8AygJ01vLx6o+rf+UBOmt5ePVH1b/ygJ01vLx6o+rf+UByXnnn3nH33FOvOqK3XVkqUpSjkqUTqSTxMB//2Q==';
 
 
	if(ctype_alnum($iSurveyID) && (strlen($iSurveyID) == 5 || strlen($iSurveyID) == 6)) { // Valid SID format
 
		// Instantiate a new RPC client
		$myJSONRPCClient = new jsonRPCClient( LS_BASEURL.'/index.php/admin/remotecontrol' );
 
		// Get a session key
		$sSessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD );
 
		if(is_array($sSessionKey)) { // Invalid session
			echo $sSessionKey['status'];
		}
		else if($sSessionKey) { // Valid session
 
			/*** Upload the image file ***/
 
			$uploadedFile = $myJSONRPCClient->upload_file($sSessionKey, $iSurveyID, $sFieldName, $sFileName, $sFileContent);
 
			foreach($uploadedFile as $key => $value) {
				echo $key . ' => ' . $value . '<br />';
			}
			echo '<br /><br />';
 
 
			/*** Create a new response  ***/
 
			$newImageData = '[{ 
				"title":"My title",
				"comment":"My comment...",
				"size":"'.$uploadedFile["size"].'",
				"name":"'.$sFileName.'", "filename":"'.$uploadedFile["filename"].'",
				"ext":"'.$uploadedFile["ext"].'" 
			}]';
			$aResponseData = array(
				$sFieldName => $newImageData
			);
			$newResponse = $myJSONRPCClient->add_response($sSessionKey, $iSurveyID, $aResponseData);
 
			echo 'Response created with ID: ';
			print_r($newResponse);
		}
 
		// Release the session key
		$myJSONRPCClient->release_session_key( $sSessionKey );
	}
	else { // Invalid SID format
		die( 'Invalid format!' );
	}
 
?>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Folgende Benutzer bedankten sich: DenisChenu

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
4 Monate 3 Wochen her #181045 von DenisChenu
Thanks :)

We must have some gist repo about remote_control

Else
f(ctype_alnum($iSurveyID) && (strlen($iSurveyID) == 5 || strlen($iSurveyID) == 6)) { // Valid SID format
No, i'm not OK with that test : you can force sid to be any int(11) , i already upload lss with sid to 1 ,101,201 etc …

I think just test if ctype_digit (why ctype_alnum ?) or strval(intval($iSurveyID)) == strval($iSurveyID).

BUT : remote_control MUST take care of it not external tool (if it's not the case : it can be a security issue).

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand .
An error happen ? Before make a new topic : remind the Debug mode .

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
4 Monate 3 Wochen her #181051 von tpartner

No, i'm not OK with that test : you can force sid to be any int(11) , i already upload lss with sid to 1 ,101,201 etc …

Yes, I understand that it could be a little more robust but I only use 6-digit IDs. :)

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
4 Monate 3 Wochen her #181057 von DenisChenu
Yes, but why testing ctype_alnum then ? Directly ctype_digit no ?

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand .
An error happen ? Before make a new topic : remind the Debug mode .

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
4 Monate 3 Wochen her #181106 von tpartner
As I've indicated in the past, I'm sure that folks with bigger PHP brains than me may have betters solutions.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
4 Monate 3 Wochen her #181115 von DenisChenu
It's not brain … it's just because i more use PHP (and you more use JS).

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand .
An error happen ? Before make a new topic : remind the Debug mode .

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Jetzt loslegen!

Melden Sie sich jetzt an, und erstellen Sie in wenigen Minuten Ihre erste Umfrage.

Account einrichten

Abonnieren Sie unseren Newsletter

Abonnieren Sie unseren Newsletter für alle Neuigkeiten rund um LimeSurvey
captcha