Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#815127
Hi there,

Is there a way to upload files to a case without using an input document via the REST API?
Just like the way files are uploaded in a Grid when in the form/web entry.

i've tried leaving the values empty, but getting a 400 back:
Code: Select all
$path = $_FILES['file']['tmp_name'];
$type = $_FILES['file']['type'];
$filename = $_FILES['file']['name'];
rename($path, sys_get_temp_dir() . '/' . $filename);

$data = array(
'inp_doc_uid' => '',
'tas_uid' => '',
'app_doc_comment' => '',
'form' => (phpversion() >= "5.5") ? new CurlFile($path, $type) : '@'.$path
);

Any help is appreciated.
Thank you.
#815131
Thanks for that!
i've been using your version 1.

OK so i've disabled the old one and then imported this 1.6 version.
Code: Select all
$url = "$eformUrl/api/1.0/$eformWs/extrarest/case/$caseId/upload";
			
if ($eformUrl && $eformWs && $_FILES["file"]['name'] != '') {
	$path = $_FILES['file']['tmp_name'];
	$type = $_FILES['file']['type'];
	$filename = $_FILES['file']['name'];
	rename($path, sys_get_temp_dir() . '/' . $filename);
	$data = array(
		'file' => (phpversion() >= "5.5") ? new CurlFile($path, $type) : '@'.$path
	);
	if (curlThis($result, $url, $token, 'POST', $data)) {
		echo json_encode($result);
		exit();
	} else {
		echo $result;
		exit();
	}
My curlThis looks like:
Code: Select all
function curlThis(&$result, $url, $access_token = '', $method = 'GET', $data = array()) {
	
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		if ($access_token != '') {
			curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer " . $access_token));
		}
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		if ($method == 'POST') {
			curl_setopt($ch, CURLOPT_POST, true);
			// curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
			curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		} else if ($method == 'PUT') {
			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
			curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
		}
	
		$result = json_decode(curl_exec($ch), true);
		$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
		curl_close($ch);
	
		if ($statusCode != 200) {
			if (isset($result) and isset($result->error)) 
				$result = "Error code: {$result->error->code}\nMessage: {$result->error->message}\n";
			else 
				$result = "Error: HTTP status code: $statusCode\n";
	
			return false;
		}
		else 
			return true;
		
	}
I'm getting a HTTP status code: 0 as a response.
Any ideas?

Using the same function get list of uploaded documents and those work fine.
#815133
You can't pass the file through http_build_query(), since it will corrupt it and I recommend using curl_file_create().
Use the code listed in the code example:
https://sourceforge.net/p/pmcommunity/c ... _uidupload

I don't know what will happen if you have the same plugin installed twice, since they use the same files.
I recommend deleting both versions of the extraRest plugin and then reimport extraRest version 1.6.
#815134
My PHP is 5.4 so it doesnt have the curl_file_create() function.
Code: Select all
$data = array(
	'file' => (phpversion() >= "5.5") ? new CurlFile($path, $type) : '@'.$path
);
I've edited the curlThis to accept another param to check whether it needs to do http_build_query.

Deleted the extraRest files, from shared/sites/workflow/files/input and reimported 1.6.
Still getting a Http status code: 0 response, any ideas?
#815137
Got it!
Had to move it to a proper place first then add an @/ infront of the full path:
Code: Select all
$newFilePath =  '/usr/local/itapps/www/html/processmaker/shared/sites/workflow/files/' . basename($_FILES['file']['name']);
move_uploaded_file($_FILES['file']['tmp_name'], $newFilePath);

$data = array(
	'file' => "@/$newFilePath"
);
Thanks for the plugin! I use it alot!

Experience heightened pleasure with Cenforce 100 M[…]

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]

Betvisa clone scripts are pre-built software solut[…]