Discussions
Curl Error: couldn't open file on v1/recruiting/applications/documents
Hi,
I try to upload a pdf file via v1/recruiting/applications/documents and get the error couldn't open file "https://www.domain.com/myfile.pdf" but the URL is correct and working in the browser.
Do you have an idea what could be wrong?
Here is my PHP-Code:
$headers = [
'accept: application/json',
'content-type: multipart/form-data',
'x-company-id: ' . $settingsArr['companyId'],
'authorization: Bearer ' . $settingsArr['accessToken']
];
$postData['file'] = curl_file_create('https://www.domain.com/myfile.pdf', 'application/pdf', myfile.pdf);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $settingsArr['docUrl']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$curlResponse = curl_exec($ch);
$curlError = curl_error($ch);
$curlInfo = curl_getinfo($ch);
curl_close($ch);
Hi Andi,
Thanks for reaching out. As far as I know, curl_file_create()
expects as a first parameter the file name of a file which was previously uploaded to your server. In your example you're using https://www.domain.com/myfile.pdf
. This probably wouldn't work, as you'd have to fetch the content of the file hosted under this URL, create a temporary file locally with this content, and use the name of this temporary file in curl_file_create()
. If this file is already stored in your server, you'd use the file name directly:
$postData['file'] = curl_file_create('myfile.pdf', 'application/pdf', myfile.pdf);
Unfortunately there's not much more help we can provide in this case as the issue is not related to our API, but about file handling in PHP. Please let us know if you're still facing issues after you've been able to send the request, and we'll be happy to help.
Cheers,
Nicolas
Hi Nicolas,
thanks for your respond.
I have changed the path to a local Server-Path and now it works.
Many regards
Andi
ο»Ώ