Reputation: 21
I try to upload a PDF file in Alfresco Enterprise 4. There is my PHP calling curl action :
$curl_request = curl_init();
curl_setopt($curl_request, CURLOPT_URL, 'http://myalfresco:80/alfresco/service/api/upload?alf_ticket=TICKET_1c75b3391fc2b8a60a1ab92dd1xxx');
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_request, CURLOPT_HEADER, false);
curl_setopt($curl_request, CURLOPT_POST,true);
curl_setopt($curl_request, CURLOPT_POSTFIELDS,array('filedata'=>'@/var/tmp/QDL_Attrib_29.pdf','destination'=>'workspace://SpacesStore/71a79d5f-326d-4671-8fee-5ffef2540e2d'));
$result = curl_exec($curl_request);
And I get this error :
"status" : { "code" : 400, "name" : "Bad Request", "description" : "Request sent by the client was syntactically incorrect." },
"message" : "Required parameters are missing"
If I try to run directly my call in curl in command Line, like this, it works... I don't understand my problem...
curl -v -X POST -F filedata=@/var/tmp/QDL_Attrib_29.pdf -F destination=workspace://SpacesStore/71a79d5f-326d-4671-8fee-5ffef2540e2d http://myalfresco:80/alfresco/service/api/upload?alf_ticket=TICKET_1c75b3391fc2b8a60a1ab92dd1xxx
If I display Header of curl in Command line:
POST /alfresco/service/api/upload?alf_ticket=TICKET_1c75b3391fc2b8a60a1ab92dd1xxx HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: myalfresco
> Accept: */*
> Content-Length: **29447**
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------530a6362a7da
In PHP :
POST /alfresco/service/api/upload?alf_ticket=TICKET_1c75b3391fc2b8a60a1ab92dd1xxx HTTP/1.1
Host: myalfresco
Accept: */*
Content-Length: **339**
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------362fa1523053
It mean than curl can get the file with PHP method...
Upvotes: 2
Views: 1016
Reputation: 21
I've solved my problem like this :
$curl_request = curl_init();
curl_setopt($curl_request, CURLOPT_URL, 'http://localhost:8080/alfresco/service/api/upload?alf_ticket=<ALFRESCP_LOGIN_TICKET>');
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_request, CURLOPT_HEADER, false);
curl_setopt($curl_request, CURLOPT_POST,true);
$args = new CurlFile('<PATH_TO_THE_FILE.EXTENSION>','<MIMETYPE like image/png>','<FILENAME as it is sent for upload>');
curl_setopt($curl_request, CURLOPT_POSTFIELDS, array('destination'=>'<DESTINATION_NODEREF>','filedata'=>$args));
$result = curl_exec($curl_request);
The parameter "filedata" in Post fields must be a CurlFile for be send to Alfresco.
Upvotes: 0
Reputation: 3818
You need to pass the filename.
To be honest, I have not tested it, and I do not remember what I usually pass, but this is the code in Alfresco that returns the error:
// Ensure mandatory file attributes have been located. Need either destination, or site + container or updateNodeRef
if ((filename === null || content === null) || (destination === null && (siteId === null || containerId === null) && updateNodeRef === null))
{
exitUpload(400, "Required parameters are missing");
return;
}
My hypothesis, not tested yet, is that curl adds the filename automatically.
Upvotes: 2
Reputation: 4156
Could it be that you have already uploaded a file with the same file name to the same folder (using your command line).
Try cleaning the destination folder and executing that code again.
Note: This page suggests you can add a boolean overwrite param to force overwrite the existent file.
EDIT 1: Try checking if PHP user does have rights to access the file to attach in your request !
EDIT 2: If it still does not work, and you are sure the php user has appropriate rights to the file, try this 'filedata'=>'@/var/tmp/QDL_Attrib_29.pdf;filename=QDL_Attrib_29.pdf;type=application/pdf'
Upvotes: 1