Handling Form-based File Upload with Java Servlet or JSP :: For other versions of Commons FileUpload, the procedures may be slightly different . Retrieving Values of Ordinary Form Fields with Java Servlet / JSP http://blog.csdn.net/Aragorn_177/archive/2008/12/01/3420296.aspxHOME | There seems to be alot of posts on file upload issues, but none of the ones I looked through actually discuss how this works but it must be common.
I have a form that has an inputType: 'file' TextField on it, along with a few other normal fields. This form is for uploading a file and linking that file to a record in a database, so the details of the upload are also stored in a table.
After playing with it for a bit, it looks like I can either have a File Upload that doesn't send the other field values, or a normal HTTPRequest that sends the data but no file (I'm aware of why you can't send a file over HTTPRequest)
Here is a snippet of the form:
// Initiate the form including the action url when submitted
thisForm = new Ext.form.Form({
labelWidth: 80,
url: '../../ajax/upload/upload-scriptinst-file.php',
buttonAlign: 'left',
fileUpload: true
});
// Setup all of the fields onthe form
var scriptFile = new Ext.form.TextField({
fieldLabel: 'File',
name: 'scriptFile',
width: 200,
allowBlank: false,
inputType:'file'
});
var name = new Ext.form.TextField({
fieldLabel: 'Name',
name: 'name',
width: 200,
allowBlank: false
});
// Add the fileds to the form (using a fieldset)
thisForm.add(
scriptFile,
name
);
// Add the save button that submits the form File upload - MultiPowUpload – file upload component ActiveX/Java :: With file Uploader, the mode to upload files via HTML input fields will be to the specification that is defined in RFC 1867 (Form-based File Upload). http://file-upload.safe-install.com/HOME | AJAX forms and file uploading in Rails « RailsBlaster:: Sep 20, 2007 The best link I could find for Rails AJAX file uploading was Dave client filesystem (for security reasons), and thus, file form fields. http://railsblaster.wordpress.com/2007/09/20/ajax-forms-and-file-uploading-in-rails/HOME |
thisForm.addButton('Upload File', function(){
if (thisForm.isValid()) {
thisForm.submit({
waitMsg: 'Saving...',
failure: function(thisForm, action) {
// Fail Stuff
},
success: function(thisForm, action) {
// Success Stuff
} ASP huge file upload free download Easy to use, hi-performance ASP :: Fill out PDF forms and other electronic forms (DOC, XLS… All Converter 6.0.2 . Free Download now Free Download ASP huge file upload 2.1 from motobit.com http://3d2f.com/programs/0-252-asp-huge-file-upload-download.shtmlHOME | Working with Form 'file field' data in ASP.:: 4 posts - Last post: Jun 24, 2006It does not work for file upload fields. It works for all other form fields, but not for file upload fields. The solution: http://webforumz.com/classic-asp/6996-working-with-form-file-field-data.htmHOME |
});
}else{
// Form ain't valid stuff
}
}, thisForm);
// Render the form
thisForm.render('files-upload-form');
My questions are:
1. How do I send data from the other fields using the fileUpload:true option. The only thing I can think of is adding a param: {} set under the form submit and accessing the form items
2. How do I get a response from the server this way? I read in another thread that this method can only return XML or HTML, not JSON. But then I see another poster here say that they successfully pass JSON back to client. As you can see, the server-side script will save a file to the file system, and insert records in a database. I need to add error reporting for both actions so the user can see the reason for failure.
Of course you could always use a managed iframe panel to submit into using a standard form post...
I haven't tested it personally but reading the source tells me that other fields should be normally submitted with the form.
BTW, you create your form as new Ext.form.Form. Are you using Ext 1.x version? (I've read 2.0 sources...)
Hi Saki,
After testing that, you are correct. Just flying blind on Firebug is all.
And I even tried returning JSON Responses despite what I read earlier and it works!
With the code in my first post, here is the code on my PHP page that does the work:
$name = $_REQUEST['name'];
$target_path = ($_FILES['scriptFile']['name']);
if(!move_uploaded_file($_FILES['scriptFile']['tmp_name'], $target_path)) {
die('{"success":false, "errors":[{"errorText":"There was an error uploading the file"}]}');
}
/* Database work with the other variables goes here */
Thanks again Saki.
Red Hat's Rough Recovery From CFO Exit
Windows Live Finds a New, Pre-installed Home |