php - 使用 Curl 在 Alfresco 中上传 PDF 时出现错误 400

标签 php curl alfresco

我尝试在 Alfresco Enterprise 4 中上传 PDF 文件。我的 PHP 调用了 curl 操作:

$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);

我收到此错误:

"status" : { "code" : 400, "name" : "Bad Request", "description" : "Request sent by the client was syntactically incorrect." },
"message" : "Required parameters are missing"

如果我尝试在命令行中直接运行curl中的调用,就像这样,它会起作用...我不明白我的问题...

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

如果我在命令行中显示curl的标题:

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

在 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

这意味着curl可以用PHP方法获取文件...

最佳答案

您需要传递文件名。

说实话,我没有测试过,我也不记得我通常通过的是什么,但这是Alfresco中返回错误的代码:

// 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;
  }

我的假设(尚未测试)是curl 自动添加文件名。

关于php - 使用 Curl 在 Alfresco 中上传 PDF 时出现错误 400,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35201990/

相关文章:

php - 我可以从 php 调用 python 脚本或函数吗

java - 使用 HttpURLConnection 提交 json POST 请求

python - 使用来自 python 的 XML POST flask 服务器

liferay - 集成 Liferay 和 Alfresco

php - Wordpress - 删除动态生成的样式表?

php - 保存一行时缺少字符?

curl - 无法从一个容器 curl 到另一个容器

java - 我们如何通过java传输文件到ALFRESCO

java - 在 bootstartup 时通过 Java 代码删除工作流程

php - 使用 Redis 集群和事务