How can we upload a file using enctype="multipart/form-data" in a ColdFusion 2018 REST Service?
Mocking up a simple service;
<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>
And I have called it from POSTMAN
path : [APIPATH]/file/upload
httpmethod : POST
Headers
Content-Type : multipart/form-data
Body : form-data
key Type value
file File : document.pdf (uploaded from POSTMAN)
Response
{
"message": "Not Found",
"success": false,
"errcode": "404"
}
I have tried the Body part without the file uploaded and it gives
The form field file did not contain a file. (Error in ColdFusion log file)
{
"message": "Internal Server Error",
"success": false,
"errcode": "500"
}
My question is, why it gives 404 error while I am trying it with file uploaded?