I am doing an api in php with CURL to receive a file from a form which places it in the Cloud Object Store of IBM Cloud.
All good with pdf and txt files, but when sending image or office files when downloading them from the bucket (direct from the cloud console) they are corrupted and can not be rendered.
I have changed CURL OPTS, headers, mines types, etc ... and nothing
Has anyone gone through this? Thank you very much!
This is the function:
function setOjbect($file,$narr,$rand)
{
//Nombre del archivo
$nombre_archivo = $rand.$file[$narr]['name'];
$size = $file[$narr]['size'];
$mime = $file[$narr]['type'];
//Guarda archivo en .tmp
$vtemp = setObjectTMP($file,$narr,$rand);
//Asigna ruta .tmp
$tmp = '.tmp/'.$nombre_archivo;
$cFile = new CURLFile($tmp, $mime, basename($tmp));
$data = array( "filedata" => $cFile, "filename" => $cFile->postname,"type=".$mime);
//SI SE CARGO DE FORMA EXITOSA EL TMP
if($vtemp == 1)
{
//Envia archivo a Cloud Object Storage
$url = "CLOUD URL";
$ch = curl_init($url);
$headers = array(
"Authorization: bearer "MI TOKEN AUTH" ",
"Content-type: ".$mime.""
);
$options = array(
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => $headers
);
curl_setopt_array($ch,$options);
curl_exec($ch);
curl_close($ch);
//borramos archivo del directorio temporal
deleteOjbect($tmp);
$error = 0;
}
else
{
$error = 1;
}
return $error;
}