Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload CV file to "files" tab in career portal programmically #500

Open
BeGood20 opened this issue Nov 30, 2022 · 1 comment
Open

Upload CV file to "files" tab in career portal programmically #500

BeGood20 opened this issue Nov 30, 2022 · 1 comment

Comments

@BeGood20
Copy link

INSERT SHORT DESCRIPTION EXPLAINING THE HIGH-LEVEL REASON FOR THE NEW ISSUE HERE.

We need to upload CV file(s) to "files" tab in career portal programmically (PDF, DOC, TXT Files) but we have struggled to get this to work with the files uploading being blanks. Any advice or help is appreciated to get this sorted immediately. I have added so of the code here but have attached the TXT file which has the full code so far.

recruitment_single.txt

Current behavior

  • PDF, DOC, TXT Files not uploading to the "files" tab on careers portal

Expected behavior

  • Once you upload CV via website, the CV gets parsed and added to the dashboard but CV also needs it's file to be uploaded to the "files" tab

What has happened?

  1. Empty files get uploaded to files tab but no file name, file size or file is included

Codes in question

`function makeHttpRequestUpload($baseURL = '', $method, $options = array(), $restToken = []) {
$url = $baseURL.$method;
$postdata = $options;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $postdata,
CURLOPT_HTTPHEADER => array(
"BhRestToken: ".$restToken
),
));
$response = curl_exec($curl);
curl_close($curl);
$content = json_decode($response);
return $content;
}

function makeHttpRequestFileUpload($baseURL = '', $method, $options = array(), $options2 = array(), $restToken = []) {
$url = $baseURL.$method;
$post = file_get_contents(''.$options2.'');
$eol = "\r\n";
$separator = ''.md5(microtime()).'';
$requestBody = '';
$requestBody .= '--'.$separator. $eol;
$requestBody .= 'Content-Disposition: form-data; name="resume"; filename="'.$options.'"'. $eol;
$requestBody .= 'Content-Length: "'.strlen($post).'"'. $eol;
$requestBody .= 'Content-Type: text/html'.$eol;
$requestBody .= 'Content-Transfer-Encoding: binary'. $eol. $eol;
$requestBody .= ''.$post.''. $eol;
$requestBody .= '--'.$separator.'--'. $eol . $eol;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => $requestBody,
CURLOPT_HTTPHEADER => array(
"BhRestToken: ".$restToken,
'Content-type: multipart/form-data; boundary='.$separator.''
),
));
$response = curl_exec($curl);
curl_close($curl);
$content = json_decode($response);
return $content;
}

function attachFileToCandidate($postFileDataName, $postFileData, $candidateIDNumber){
BHConnect();
$method = 'file/Candidate/'.$candidateIDNumber.'/raw?fileType=SAMPLE&type=CV&externalID=portfolio';
$response = makeHttpRequestFileUpload($_SESSION['BH']['restURL'], $method, $postFileDataName, $postFileData, $_SESSION['BH']['restToken']);
return $response;
}

if(isset($_POST) && !empty($_POST) && !empty($_FILES)){
$postFileDataName = [
"fileName" => new CURLFILE($_FILES['resume']['name'])
];
$postFileData = [
"file" => new CURLFILE($_FILES['resume']['tmp_name'])
];
$resumeData = parseToCandidate($postFileData);
if (isset($resumeData->html)) {
$postData = [
"firstName" => $_POST['first_name'],
"lastName" => $_POST['last_name'],
"email" => $_POST['email'],
"description" => $resumeData->html,
"name" => $_POST['first_name']." ".$_POST['last_name'],
"category" => ["id"=> 2000021],
"mobile" => $_POST['phone'],
"source" => $_POST['description'],
"comments" => $_POST['cover_letter'],
"companyURL" => $_POST['company_website'],
"desiredLocations" => $_POST['desired_locations'],
"customText1" => $_POST['linkedin'],
"customText2" => $_POST['sponsorship'],
"status" => "Pre-Registered",
];
$check_candidate_exist = checkCandidateExist($_POST['first_name'],$_POST['last_name'],$_POST['email']);
if (isset($check_candidate_exist->total) && $check_candidate_exist->total > 0) {
$candidate = new stdClass();
$candidate->changedEntityId = $check_candidate_exist->data[0]->id;
} else {
$candidate = getBHCreateCandidate($postData);
}
if (isset($candidate->changedEntityId)) {
$candidateIDNumber = $candidate->changedEntityId;
$attachedFile = attachFileToCandidate($postFileDataName, $postFileData, $candidateIDNumber);
$newPostData = [
"dateWebResponse"=> "1370522348880",
"candidate"=> ["id"=> $candidate->changedEntityId],
"jobOrder"=> ["id"=>$_REQUEST['id']],
"comments" => $_POST['cover_letter']
];
$applyJob = submitBHJobSubmission($newPostData);
if (isset($applyJob->changeType)) {
$_SESSION['success_msg'] = "You have applied successfully.";
} else {
$_SESSION['error_msg'] = "Something went wrong. Please try again.";
}
}
} else {
$_SESSION['error_msg'] = "Something went wrong on CV uploads";
}
}
?>`

@pbearne
Copy link

pbearne commented Nov 30, 2022

Hi Guys

Have you looked at Matador Jobs this is built in and working

Reach out for help [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants