我正在尝试将文件上传到ColdFusion 10中的REST端点。我尝试了各种方法,但没有一种方法有效...
REST端点定义看起来像这样......
<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>
答案 0 :(得分:0)
@siromega我不确定你是否找到了解决方案,但我遇到了支持文件上传的taffy.io。如果你这样做,请你发布更新吗?
图像字段的标题不同,图像字段的内容采用二进制编码。
https://github.com/atuttle/Taffy/wiki/So-you-want-to:-Upload-a-file-via-your-API
希望它有所帮助。
答案 1 :(得分:0)
最近,我使用ColdFusion REST创建了一个文件上传API。这是一个示例,我们接受一个文件(csv或excel)并将其转换为json。我们已在ColdFusion Administrator中注册了此REST服务。用于上载文件的参数名称是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);
}
}