Uploading Resume and motivation fails (apply_joborder)

46 views
Skip to first unread message

Ka-Sing Chou

unread,
May 30, 2016, 11:48:03 AM5/30/16
to CATS API, Marien Dongstra, k.c...@onsweb.nl
Hello,

I tried to do an apply_joborder api call with CURL. See the routine here below.


INPUT 
$option = array (
    [transaction_code] => 147d13863c84e3ea3843f8f31d4917f9,
    [44727] => @/var/www/uwnota.dev/public_html/sites/default/files/Test CV.docx,
    [44754] => @/var/www/uwnota.dev/public_html/sites/default/files/Test Motivatie.docx,
    [44730] => Onsweb Test,
    [44733] => Onsweb Test,
    [44739] => sdfasf,
    [44742] => NULL,
    [44745] => NULL,
    [44748] => NULL,
    [44751] => 0654763081,
    [id] => 219610,
);

FUNCTION
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://infomedics.catsone.nl/api/apply_joborder');
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $options);
$result=curl_exec ($ch);
curl_close ($ch);

RESULT
<response success="false">
    <error code="412">44727 is a required parameter for Upload CV.</error>
</response>

QUESTION
What am I doing wrong?

Friendly Regards,

Ka-Sing Chou

Aaron Baluczynski

unread,
May 31, 2016, 10:06:55 AM5/31/16
to CATS API, m.don...@onsweb.nl, k.c...@onsweb.nl
Hi,

You may need to set the following curl option:

curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);


Also verify that the file permissions are correct.

Hope that helps.

Ka-Sing Chou

unread,
Jun 2, 2016, 4:15:49 AM6/2/16
to CATS API, m.don...@onsweb.nl, k.c...@onsweb.nl
Dear Aaron, 

The file permissions are correct. Setup the Curl_setopt line. I still get the same message (44727 is a required parameter for Upload CV. 1).

Aaron Baluczynski

unread,
Jun 2, 2016, 10:09:36 AM6/2/16
to CATS API, m.don...@onsweb.nl, k.c...@onsweb.nl
Hi,

The problem is the file is not being sent to the API. You'll have to dig into why CURL isn't sending it. Maybe this is applicable: http://stackoverflow.com/questions/25934128/curl-file-uploads-not-working-anymore-after-upgrade-from-php-5-5-to-5-6

Aaron

Ka-Sing Chou

unread,
Jun 8, 2016, 10:53:42 AM6/8/16
to CATS API, m.don...@onsweb.nl, k.c...@onsweb.nl
Thanks Aaron! That helped a lot.

In any latest PHP versions, instead of @{file-paths}, one can use new \CURLFile({file-path}

For those who are troubling with uploading resume's or files, here is the snippet which I used in a Drupal form:

.......
 
function onsweb_apply_form_validate($form, &$form_state) {
  $file
= file_save_upload('wb_file_resume', array(
   
'file_validate_extensions' => array('docx doc pdf'),
 
));
 
if ($file) {
   
if ($file = file_move($file, 'public://')) {
      $form_state
['values']['wb_file_resume'] = $file;
   
} else {
      form_set_error
($key, t('Failed to write the uploaded file the site\'s file folder.'));
   
}
 
} else {
    form_set_error
($key, t('No file was uploaded.'));
 
}
}

// FYI, this function is being called after the validation function
function onsweb_apply_form_submit($form, &$form_state) {

  $options
= array('transaction_code' => '{{YOUR_CODE_HERE}}');
  $options
['id'] = $form_state['values']['item_id']; // The ID of the vacancy as in context
 
 
foreach ($form_state['values'] as $key => $value) {
   
if (strstr($key, 'wb_file_')) {
      $file
= $value;
      $file
->status = FILE_STATUS_PERMANENT; // Drupal thingy
      file_save
($file);
       $wrapper
= file_stream_wrapper_get_instance_by_uri($file->uri);
      $options
[str_replace('wb_file_', '', $key)] = new \CURLFile($wrapper->realpath());
   
}
   
if (strstr($key, 'wb_') && !strstr($key, 'wb_file_')) $options[str_replace('wb_', '', $key)] = $value;
 
}

 
// Copy pasted the _do function from the Catsone API V2

  $ch
= curl_init();
  curl_setopt
($ch, CURLOPT_URL, 'https://infomedics.catsone.nl/api/apply_joborder');

  curl_setopt
($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt
($ch, CURLOPT_CONNECTTIMEOUT, 90);
  curl_setopt
($ch, CURLOPT_TIMEOUT, 90);
  curl_setopt
($ch, CURLOPT_FAILONERROR, true);
  curl_setopt
($ch, CURLOPT_POST, true);
 
if (defined('CURLOPT_SAFE_UPLOAD')) {
    curl_setopt
($ch, CURLOPT_SAFE_UPLOAD, false);
 
}
  curl_setopt
($ch, CURLOPT_POSTFIELDS, $options);
  curl_setopt
($ch, CURLOPT_HTTPHEADER, array('Expect:'));
  $result
= curl_exec($ch);
  $xml
= simplexml_load_string($result);
  curl_close
($ch);


 
if (!$xml) {
    drupal_set_message
(t('Something Wong'), 'error');
 
}
 
if ($xml['success'] !== 'true') {
    drupal_set_message
(t('All Cool'));
 
}
}

Cheers!

Friendly regards

Ka-Sing Chou




On Monday, May 30, 2016 at 5:48:03 PM UTC+2, Ka-Sing Chou wrote:
Reply all
Reply to author
Forward
0 new messages