Expand my Community achievements bar.

Upload file to AEM Dam via php script

Avatar

Level 1

Hello,

I am trying to upload some file via a php script .

Here is my script

// Check if file exists
if (file_exists($file_path)) {
// Initialize cURL session
$ch = curl_init();

// Set cURL options
curl_setopt($ch, CURLOPT_URL, $aem_url . "/" . $filename);
curl_setopt($ch, CURLOPT_USERPWD, $aem_user . ":" . $aem_password);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => new CURLFile($file_path)));

// Execute cURL session
$response = curl_exec($ch);

// Check for errors
if (curl_errno($ch)) {
echo "Error uploading file " . $filename . ": " . curl_error($ch) . "<br>";
} else {
echo "File " . $filename . " uploaded successfully.<br>";
}

// Close cURL session
curl_close($ch);
} else {
echo "File " . $filename . " does not exist.<br>";
}

 

and this is the error I am getting.

Upload error: SSL certificate problem: unable to get local issuer certificate

 

Should I first generate an API token or what am I missing?

 

Thanks for your advices

Cedric

 

3 Replies

Avatar

Level 6

Hi @ReymondCe ,

 

Since you are trying to upload a file via a third party application you will need the authentication sorted out, a basic authentication will not work, so you will need to use a service credential. This tutorial should help you figure this out - https://experienceleague.adobe.com/en/docs/experience-manager-learn/getting-started-with-aem-headles... which leverages Technical accounts for authentication.

 

Regards,

Anupam Patra

Avatar

Level 1

Thank for the info.

I managed to fix the issue, using the curl cacert.pem

Now file is uploaded but I can't find where...

Avatar

Community Advisor

Hi @ReymondCe 

 

The path value is not mentioned in the code so it would have been directly created under the root (/) path. You can check that from CRXDE - http://localhost:4502/crx/de/index.jsp

 

Thanks

Narendra