5

我们如何在 ColdFusion 2018 REST 服务中使用 enctype="multipart/form-data" 上传文件?

模拟一个简单的服务;

<cfcomponent rest="true" restpath="file">

   <cffunction name="postUpload" restpath="upload" access="remote" returntype="struct" httpmethod="POST" produces="application/json">

       <cfset var response = {} />  

       <cffile 
          action = "upload"
          filefield = "file"
          destination = "D:\files\temp\"
          accept = "application/pdf"
          nameConflict = "overwrite"
          result="myFile"
        >

        <cfset response = myFile />

        <cfreturn response>
   </cffunction>

</cfcomponent>

我从邮递员那里打电话给它

路径:[APIPATH]/文件/上传

http方法:POST

标头

内容类型:多部分/表单数据

正文:表单数据

  key       Type      value
  file      File    : document.pdf (uploaded from POSTMAN)

回复

 {
   "message": "Not Found",
   "success": false,
   "errcode": "404"
 }

我已经尝试了没有上传文件的 Body 部分,它给出了

The form field file did not contain a file. (Error in ColdFusion log file)

{
  "message": "Internal Server Error",
  "success": false,
  "errcode": "500"
}

我的问题是,为什么在我尝试上传文件时会出现 404 错误?

4

0 回答 0