CFFILE - 使用组件上传文件 [英] CFFILE - Uploading a file using a component

查看:309
本文介绍了CFFILE - 使用组件上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,我想提交给一个组件进行处理(CRUD行为),问题是似乎传递multipart / form-data到一个组件以某种方式丢失文件位置。当它到达组件的应该上传文件的部分,我得到臭名昭着的表单字段不包含文件错误。

I have a form that I would like to submit to a component for processing (CRUD behaviors), the problem is it seems passing multipart/form-data to a component somehow looses the file location. When it gets to the part of the component that should be uploading the file I get the infamous form field did not contain a file error.

我不是100%确定为什么会发生,但如果我直接提交表单到.cfm页面执行 cffile action一切按预期工作,但如果.cfm页面执行以下操作:

I am not 100% sure why this happening but if I submit the form directly to a .cfm page that performs the cffile action everything works as expected, but if the .cfm page does something like:

<cfobject name="process_form" component="processor" />
<cfset result = process_form.upload( form ) />

并且组件processor试图做上传,我得到的表单字段不包含文件。

and the component "processor" tries to do the upload, I get the form field did not contain a file.

我的处理器看起来像:

    <cfcomponent name="processor">
      <cffunction name="upload" returntype="string">
      <cfargument name="form_data" type="struct" />
      <cffile action="upload" filefield="#arguments.form_data.file_1#" ...>
          [ ... ]
      </cffunction>
    </cfcomponent>



.file_1 没有#符号,我得到错误:

One thing to note, is if I try use the variable arguments.form_data.file_1 without the # signs around it, I get the error:

The form field arguments.form_data.file_1 did not contain a file.

如果我把#符号放在变量上,我得到:

If I put the # signs around the variable I get:

The form field C:\JRun4\servers\cfusion\SERVER-INF\temp\cfusion-war-tmp\neotmp7350969777287007477.tmp did not contain a file. 

有关如何解决此问题的任何想法吗?我宁愿将所有我的处理动作放在一个组件中,但现在我似乎不能做这项工作。

Any idea on how to fix this issue? I would rather have all my processing actions inside a component, but right now I can't seem to make that work.

谢谢!

推荐答案

使用时不需要使用完整的变量名称。 cffile 标记 - 您只需要表单字段名称,例如:

You shouldn't need to use the full variable name when using a cffile tag--you just need the form field name, so something like:

<cffile action="upload" filefield="file_1" ...>

应该就足够了。 FORM 结构字段保存临时文件的位置,但是cffile标签不需要它(我的图像的id直接访问 FORM struct基于您提供的字段名)。

should suffice. The FORM struct field holds the location of the temporary file, but the cffile tag doesn't need that (I'd image that id directly accesses the FORM struct on the backend based on the fieldname you've provided).

这篇关于CFFILE - 使用组件上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆