Upload file to AEM Dam via php script | Community
Skip to main content
November 29, 2024
Solved

Upload file to AEM Dam via php script

  • November 29, 2024
  • 1 reply
  • 882 views

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

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by narendragandhi

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

1 reply

anupampat
Community Advisor
Community Advisor
November 29, 2024

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-headless/authentication/service-credentials which leverages Technical accounts for authentication.

 

Regards,

Anupam Patra

ReymondCeAuthor
November 29, 2024

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...

narendragandhi
Community Advisor
narendragandhiCommunity AdvisorAccepted solution
Community Advisor
November 30, 2024

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