File uploads in ColdFusion 10's REST API framework
I am trying to upload files to a REST endpoint in ColdFusion 10. I've tried a variety of approaches and none have worked...
The REST endpoint definitions look something like this...
<cffunction name="createDocument" access="remote" returnType="String" returnformat="JSON" httpMethod="POST" restPath="/document/">
<cfargument name="Authorization" type="string" required="true" restargsource="Header">
<cfargument name="folder" type="any" required="true" restargsource="Form">
<cfargument name="cabinet" type="any" required="true" restargsource="Form">
<cfargument name="filedata" type="bindary" required="true" restargsource="Form">
[...]
</cffunction>
@siromega I am not sure if you ever find a solution for this but I came across taffy.io that supports file uploads. If you did, could you please post an update?
Headers for the image field are different and content of the image field is in binary encoding.
https://github.com/atuttle/Taffy/wiki/So-you-want-to:-Upload-a-file-via-your-API
Hope it helps.
Recently i have created a file upload API using ColdFusion REST. Here is a sample in which we are accepting a file (csv or excel) and converting it to json. We have registered this REST service in ColdFusion Administrator. The Parameter name against which the file is uploaded is fileParam.
component output="false" restpath="/upload"
{
remote any function uploadFile() httpmethod="POST" consumes="multipart/form-data" produces="application/json" {
destination = getTempDirectory();
uploadDetails = FileUpload(destination, "fileparam", "text/csv,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "overwrite");
fileSeparator = "";//make platform independent
filePath = uploadDetails.SERVERDIRECTORY & fileSeparator & uploadDetails.ATTEMPTEDSERVERFILE;
cfspreadsheet(action = "read", src = filePath, excludeHeaderRow = false, query = "data");
return serializejson(data);
}
}
链接地址: http://www.djcxy.com/p/31252.html
上一篇: 从泛型类中返回一个数组