Copy link to clipboard
Copied
I am attempting to implement a REST endpoint that accepts a multi-part form request that includes form data as well as a file upload. Is that even possible? Is it possible to just accept a file upload and nothing else (e.g. specify a unique ID in the URL and POST/PUT data in the request body)? I've tried numerous things and have been unable to successfully implement a REST endpoint that accepts a file upload...
Copy link to clipboard
Copied
The following method, unlike those above, will work. It requires you to know the MIME type of the binary file you wish to upload. This example uploads a PDF document.
uploader.cfm
<cfset restInitApplication(expandPath("."))>
<cfhttp url="http://localhost:8500/rest/myRestApp/myService" method="post">
<cfhttpparam file="C:\temp\testDoc.pdf" mimetype="application/pdf" name="myFile" type="file">
</cfhttp>
service.cfc
<cfcomponent rest="true" restpath="/myService">
<cffunction name="getFile" access="remote" httpMethod="POST" returntype="string">
<cffile action="upload" accept="application/pdf" filefield="myFile" nameconflict="overwrite" destination="C:\Users\BKBK\Desktop\testFile.pdf">
<cfreturn "File uploaded!">
</cffunction>
</cfcomponent>
Copy link to clipboard
Copied
We need to allow all file types to be uploaded. We cannot constrain ourselves to just a few file types.
Copy link to clipboard
Copied
No problem at all. Use the wildcard for MIME type, as follows:
<cfhttpparam mimetype="*">
<cffile accept="*">
Copy link to clipboard
Copied
Did the wildcards help?
Copy link to clipboard
Copied
Has there been any useful update to this post?