Michael George
Michael George

Reputation: 43

FileUpload error - "The form field fileInput did not contain a file" (CFML - FW/1)

I'm trying to upload a file on a ColdFusion site and am receiving the following error:

"The form field fileInput did not contain a file."

The file along with some text values are submitted through a form on an Edit page. The form is submitted to the "save" method in the controller, which sends two calls to fileService. The text values are passed as expected and updating them works fine. When I dump the RC Scope struct "fileInput" (the name of the input I am using to get the file) shows as [empty string]. It is not shown in the Form scope at all. Does anyone have an idea on what could be causing the issue with this? There are a couple of answered questions that are related to forms that use cffile (tags), but everything on the site I'm working on uses FileUpload (cfscript), so I'm not sure how to apply those answers here.

FYI The site uses Framework One (FW/1 version 4.1) as its MVC framework. I'm using ColdFusion 2016. Following are snippets of the code being used.


View: Edit.cfm

<form action="#BuildURL( action='file.save' )#" name="filesForm" method="post" enctype="multipart/form-data">
  <input id="file_id" name="file_id" type="hidden" value="#rc.file_id#">
  <div class="form-group">
    <label for="name">File Name</label>
    <input type="text" class="form-control" id="name" name="name" placeholder="Enter File Name" value="#rc.name#">
  </div>
  <div class="form-group">
    <label for="fileInput">File Upload</label>
    <input type="file" id="fileInput" name"fileInput"> 
  </div>
  <div class="form-group">
    <button type="submit" class="btn btn-primary" name="Submit">Save</button>
  </div>
</form>

Controller: file.cfc

public void function edit(rc){
  if (StructKeyExists(rc, 'file_id') && rc.file_id > 0){
    var q = fileService.getFile(rc.file_id);
    rc.file_id = q.file_id;
    rc.name = q.name;
  }
}

public void function save(required struct rc){
  rc.file_id = variables.fileService.save(rc.file_id, rc.name);

  param name = "rc.fileInput" default="";
  rc.result = variables.fileService.uploadFile(file = "fileInput");

  variables.fw.redirect(action='file.edit', append='file_id', queryString = "msg=updated");
}

Service: file.cfc

struct function uploadFile(required string file){
  fileUploadResult = FileUpload(getTempDirectory(), arguments.file, "application/pdf", "MakeUnique");
}

Upvotes: 2

Views: 1075

Answers (3)

Michael George
Michael George

Reputation: 43

Turns out the issue was in the file input tag. I'd left out the 'equals' sign in the name declaration (i.e. name="fileInput"), which is why the file was not included. Unbelievable... Everything else worked after I fixed that, though I will take the suggestions to clean up the naming. Thanks everyone for your help.

Upvotes: 1

jonesk
jonesk

Reputation: 113

Did you try dumping the rc scope variable and what file are you trying to upload make sure it isnt an empty text file.

Upvotes: 0

Yieng Ly
Yieng Ly

Reputation: 129

I am not familiar with FW/1, but maybe in public void function save(), fileInput should be rc.fileInput, i.e.

 rc.result = variables.fileService.uploadFile(file = rc.fileInput);

Upvotes: 0

Related Questions