如何在 Windows 中使用 cURL 将文件上传到 Alfresco?

How to use cURL in Windows to upload a file to Alfresco?

我正在尝试使用如下命令将文件上传到 Alfresco WS restful:

C:\Users\user>curl -v -k -X POST --user admin:admin  -F filedata=C:/temp/wpapper.pdf  -F siteid=documents  -F     containerid=documentLibrary  -F uploaddirectory=PUBLIC  -F     filename=wpapper.pdf  -F contenttype="application/pdf"      http://10.1.1.55:8080/alfresco/service/api/upload

Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 10.1.1.55...
* Connected to 10.1.1.55 (10.1.1.55) port 8080 (#0)
* Server auth using Basic with user 'admin'
> POST /alfresco/service/api/upload HTTP/1.1
> Host: 10.1.1.55:8080
> Authorization: Basic Z2xvbWFyb246c2VxMDk4
> User-Agent: curl/7.46.0
> Accept: */*
> Content-Length: 715
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------5ee452c8955311dc
>
< HTTP/1.1 100 Continue
< HTTP/1.1 400 Bad Request
< Server: Apache-Coyote/1.1
< Cache-Control: no-cache
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Pragma: no-cache
< Content-Type: application/json;charset=UTF-8
< Content-Length: 362
< Date: Wed, 18 May 2016 14:03:47 GMT
< Connection: close
<
{
    "status" :
  {
    "code" : 400,
    "name" : "Bad Request",
    "description" : "Request sent by the client was syntactically     incorrect."
  },

  "message" : "Required parameters are missing",
  "exception" : "",

  "callstack" :
  [

  ],

  "server" : "Community v5.1.0 (r122274-b3) schema 9.016",
  "time" : "18/05/2016 10:03:47"
}

* Closing connection 0

Alfresco's manual for File upload:

Upload file content and meta-data into repository.

POST /alfresco/service/api/upload

HTML form data

  • filedata, (mandatory) HTML type file
  • You must specify one of:
    • destination (the folder NodeRef where the node will be created)
    • updateNodeRef (the NodeRef of an existing node that will be updated)
    • siteid and containerid (the Site name and the container in that site >where the document will be created).
  • uploaddirectory - name of the folder (either in the site container or the destination) where the document will be uploaded. This folder must already exist
  • description - Description for a version update (versionDescription)
  • contenttype - The content type that this document should be specialised to
  • majorversion
  • overwrite
  • thumbnails

Return content

  • nodeRef

Return status: STATUS_OK (200)

The web script description document specifies the following options:

_________________________________________
Value ------ Description
___________________________________________

json -------> The default response format

user -------> The authentication access
required ---> The transaction level
any   The format style
___________________________________________

PS.: 目录"PUBLIC"和站点"documents"已经存在。

一种方法是在打开开发者工具的情况下使用 Chrome 通过共享上传文件。在网络 -> XHR 选项卡上,您将看到上传请求,然后可以右键单击并 select "Copy as cURL"。然后您可以粘贴 cURL 命令并根据需要进行调整。