-
Code for uploading any file type
Question asked by visitor thakkarsaurabh
I want to write a code for file uploading and file may be of any type i.e. text, jpeg, html etc...... i want to select a file from my machine and i have to save it on our companies database How to do this......
-
Junior Member
Re: Code for uploading any file type
Sorry I have not currently code for upload file but I suggest download orally file upload jar and make request's content type is multipart.
-
Junior Member
Re: Code for uploading any file type
1.create a html
<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION = "upload.jsp">
<INPUT TYPE="FILE" NAME="Filename">
<INPUT TYPE="SUBMIT" VALUE="Submit">
<INPUT TYPE="RESET" VALUE="Reset">
</FORM>
2.upload.jsp
copy commons-fileupload-1.0.jar in lib folder
and import org.apache.commons.fileupload.* ; in ur class
// Check that we have a file upload request
boolean isMultipart = FileUpload.isMultipartContent(request);
// Create a new file upload handler
DiskFileUpload upload = new DiskFileUpload();
// Set upload parameters
/*
upload.setSizeThreshold(yourMaxMemorySize);
upload.setSizeMax(yourMaxRequestSize);
upload.setRepositoryPath(yourTempDirectory);
*/
// Parse the request
List items = upload.parseRequest(request); /* FileItem */
// Process the uploaded Field Items
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField()) {
processFormField(item);
}
}
// Process the uploaded FILE items
iter = items.iterator();
while (iter.hasNext())
{
FileItem item = (FileItem) iter.next();
if (!item.isFormField()) {
processUploadedFile(item);
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules