ATTACHMENT WITH CATS CANDIDATE UPLOADING BROKEN IMAGE

42 views
Skip to first unread message

Ahsan Hussain

unread,
Sep 30, 2016, 6:13:56 AM9/30/16
to CATS API v3
Hi,

I'm trying to attach image to candidate record by using following code in laravel, but the images are getting uploaded brokenly, please let me know where i'm going wrong and also let me know if there is any library of catsone for laravel.

Code:


I'm using V3 of cats and its document link i'm following is : https://api.catsone.com/v3/docs/#candidates-upload-an-attachment

$imageName = time().'.'.$request->image->getClientOriginalExtension();
$request->image->move(public_path('images'), $imageName);
$imageName = realpath(public_path('images') . '/1475160618.png');

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.catsone.com/v3/candidates/175294227/attachments?filename=1122.png",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => 'data:image/png;base64,'.base64_encode(file_get_contents($imageName)),
CURLOPT_HTTPHEADER => array(
"authorization: Token 3***********************************3e",
"cache-control: no-cache",
"content-type: application/octet-stream",
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
dd($err);
} else {
dd($response);
}


Above is my code i'm using to add an attachment.

Anthony Allan

unread,
Oct 3, 2016, 12:55:25 PM10/3/16
to CATS API v3
Hi there,

The docs mention `--data-binary @filename.txt` as the way to pass in the attachment. The equivalent of that using php curl is to change your `CURLOPT_POSTFIELDS` line to `CURLOPT_POSTFIELDS => file_get_contents($imageName)`. There's no need to base64 encode for this endpoint.

Ahsan Hussain

unread,
Oct 10, 2016, 11:08:18 AM10/10/16
to CATS API v3
@Anthony

Now it has starting returning

{
  "message": "Internal server error."
}

My request Id is

X-Request-ID 9f3e3add-bc86-4254-956c-5341e9108519

Anthony Allan

unread,
Oct 13, 2016, 2:12:51 PM10/13/16
to CATS API v3
Thanks your for patience, this issue has now been resolved. 

Ahsan Hussain

unread,
Oct 18, 2016, 11:29:56 AM10/18/16
to CATS API v3
Thanks.
Reply all
Reply to author
Forward
0 new messages