无法将映像上载到Coldfusion REST API服务
我正在使用CF10RESTAPI服务,并试图上传一个用户的配置文件图片 服务方法尝试将此映像保存到目标:无法将映像上载到Coldfusion REST API服务,rest,coldfusion,Rest,Coldfusion,我正在使用CF10RESTAPI服务,并试图上传一个用户的配置文件图片 服务方法尝试将此映像保存到目标: <cfcomponent rest="true" restpath="/users"> <cffunction name="saveProfilePicture" access="remote" httpmethod="POST" restpat
<cfcomponent rest="true"
restpath="/users">
<cffunction name="saveProfilePicture"
access="remote"
httpmethod="POST"
restpath="{userid}/profilePicture"
returntype="any">
<cfargument name="uploadedImage" required="true"/>
<cfargument name="userid" required="true" restargsource="Path"/>
<cffile
action="upload"
destination="#upload_path#"
fileField="uploadedImage"
result="profilePicture"
accept="image/jpg"
/>
</cffunction>
</cfcomponent>
我尝试按如下方式呼叫此服务:
<form method="POST" enctype="multipart/form-data" action="#path#/users/#userid#/profilePicture">
<input type="file" name="uploadedImage"/>
<input type="submit" name="btn_submit_profilePicture" id="btn_submit_profilePicture"
value="Submit"/>
</form>
打完这个电话后,我收到一条错误消息“不支持的媒体类型”
如果我使用cfhttp,我会遇到同样的问题:
<cfhttp url="#path#/users/#userid#/profilePicture"
result="restResult" method="POST" multipart="true">
<cfhttpparam file="someimage.jpg" mimetype="image/jpg"
name="uploadedImage" type="file"/>
</cfhttp>
我试着四处搜索,但找不到有效的解决方案。
我现在还不能使用框架,因为大部分API都已经通过CF REST API实现了,所以我想我还是坚持使用它吧
任何帮助都将不胜感激。谢谢。按照以下方式更改代码并进行测试
<cfcomponent rest="true"
restpath="/users">
<cffunction name="saveProfilePicture"
access="remote"
httpmethod="POST"
restpath="{userid}/profilePicture"
returntype="any">
<cfargument name="uploadedImage" restargsource="form"/>
<cfargument name="userid" restargsource="Path"/>
<cffile
action="upload"
destination="#upload_path#"
result="arguments.uploadedImage"
accept="image/jpg,image/jpeg"
/>
</cffunction>
</cfcomponent>
按照以下方式更改代码并进行测试
<cfcomponent rest="true"
restpath="/users">
<cffunction name="saveProfilePicture"
access="remote"
httpmethod="POST"
restpath="{userid}/profilePicture"
returntype="any">
<cfargument name="uploadedImage" restargsource="form"/>
<cfargument name="userid" restargsource="Path"/>
<cffile
action="upload"
destination="#upload_path#"
result="arguments.uploadedImage"
accept="image/jpg,image/jpeg"
/>
</cffunction>
</cfcomponent>
您试图上载的文件的实际mime类型是什么?对ColdFusion 10中的cffile
标记进行了更改,默认情况下,它实际评估文件的mime类型,而不仅仅是文件扩展名。查看此博客条目-。最后,他给出了一个使用fileGetMimeType
函数获取文件mime类型的示例。创建一个测试页面,并对您正在上载的文件使用该页面,以查看它看到的mime类型。我看到您的cfc的cffile标记中有accept=“image/jpg”
。你上传了一个真实的jpg文件吗?@Miguel-F@jules好的,所以我用fileGetMimeType检查了文件的mime类型,它是image/jpeg
。我在cfhttp调用和服务cfc中进行了更改,以使用此mime类型,但仍然遇到相同的问题。您尝试上载的文件的实际mime类型是什么?对ColdFusion 10中的cffile
标记进行了更改,默认情况下,它实际评估文件的mime类型,而不仅仅是文件扩展名。查看此博客条目-。最后,他给出了一个使用fileGetMimeType
函数获取文件mime类型的示例。创建一个测试页面,并对您正在上载的文件使用该页面,以查看它看到的mime类型。我看到您的cfc的cffile标记中有accept=“image/jpg”
。你上传了一个真实的jpg文件吗?@Miguel-F@jules好的,所以我用fileGetMimeType检查了文件的mime类型,它是image/jpeg
。我在cfhttp调用和服务cfc中进行了更改,以使用这种mime类型,但仍然遇到同样的问题。