Photo Upload

Ads
 

Photo Upload

View Answers

May 16, 2008 at 6:35 PM

Hi


<%@ page import="java.io.*" %>

<%
//to get the content type information from JSP Request Header
String contentType = request.getContentType();
//here we are checking the content type is not equal to Null and
// as well as the passed data from mulitpart/form-data is greater than or
//equal to 0
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
DataInputStream stream = new DataInputStream(request.getInputStream());
//we are taking the length of Content type data
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
//this loop converting the uploaded file into byte code
while (totalBytesRead < formDataLength) {
byteRead = stream.read(dataBytes, totalBytesRead,formDataLength);
totalBytesRead += byteRead;
}

String file = new String(dataBytes);
//for saving the file name
String saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf(" ") + 1,saveFile.indexOf("\""));
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
int pos;
//extracting the index of file
pos = file.indexOf("filename=\"");
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;

// creating a new file with the same name and writing the
//content in new file
FileOutputStream fileOut = new FileOutputStream(saveFile);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();

%><Br/><table border="1" cellspacing="0" cellpadding="0">
<tr><td><b>You have successfully upload the file by the name of:</b>
<% out.println(saveFile); %></td></tr></table> <%
}
out.println("image upload successfully");
out.println("<br/><a href=fileuploadForm.jsp><b>Back to Home</b></a>");
%>

----------------------------

Read for more information.

http://www.roseindia.net/jsp/

Ads









Related Tutorials/Questions & Answers:
upload photo in xcode
upload photo in xcode  how can i upload a photo in a view in xcode? i am a beginner in xcode please help me
Photo upload, Download
Photo upload, Download  Hi I am using NetBeans IDE for developing... am loading photo. BufferedImage image=null; JFileChooser chooser = new...()); } } Here I'll get path of the photo in local machine in variable "path" (I
Advertisements
Upload Photo to Server
Upload Photo to Server  Hi I am using NetBeans IDE for developing... i am loading photo. BufferedImage image=null; JFileChooser chooser...()); } } Here I'll get path of the photo in local machine in variable "path
photo uploading
photo uploading  i want the code upload the image in oracle database
photo album
photo album  while syncing photos to my photo album in my iphone, the photo albumj ust got crashed i guess. Under photos option i just have the camera roll option now!! What should i do to get the photo album back
photo viwer
photo viwer  i need coding for photo viewer using jsp mysql   Please visit the following link: http://www.roseindia.net/jsp/downloadimage.shtml
UPLOAD
UPLOAD  how to upload image using html
Gallery Photo
Gallery Photo  I need to display a photo gallery with the path stored in oracle with the possibility of their supprission (photo management) (with jsf or with jsp)   hi friend, Do not do such task using JSP, Better
Adding photo to iPhone simulator
Adding photo to iPhone simulator  Hi, there is no photo in my iPhone simulator.. how can i add one? Please suggest. Thanks
save uiimage to photo library
save uiimage to photo library  How to saved the clicked picture on camera roll in iPhone. I always want to write the file into photo library.   Save UIImage to photo library Creating a camera application in iPhone need
ModuleNotFoundError: No module named 'mera_photo'
ModuleNotFoundError: No module named 'mera_photo'  Hi, My Python... 'mera_photo' How to remove the ModuleNotFoundError: No module named 'mera_photo' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'natgeo_photo'
ModuleNotFoundError: No module named 'natgeo_photo'  Hi, My Python... 'natgeo_photo' How to remove the ModuleNotFoundError: No module named 'natgeo_photo' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'natgeo_photo'
ModuleNotFoundError: No module named 'natgeo_photo'  Hi, My Python... 'natgeo_photo' How to remove the ModuleNotFoundError: No module named 'natgeo_photo' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'photo-org'
ModuleNotFoundError: No module named 'photo-org'  Hi, My Python... 'photo-org' How to remove the ModuleNotFoundError: No module named 'photo... have to install padas library. You can install photo-org python with following
ModuleNotFoundError: No module named 'photo-calendar'
ModuleNotFoundError: No module named 'photo-calendar'  Hi, My... named 'photo-calendar' How to remove the ModuleNotFoundError: No module named 'photo-calendar' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'photo-dl'
ModuleNotFoundError: No module named 'photo-dl'  Hi, My Python... 'photo-dl' How to remove the ModuleNotFoundError: No module named 'photo-dl... to install padas library. You can install photo-dl python with following
ModuleNotFoundError: No module named 'photo-gen'
ModuleNotFoundError: No module named 'photo-gen'  Hi, My Python... 'photo-gen' How to remove the ModuleNotFoundError: No module named 'photo... have to install padas library. You can install photo-gen python with following
ModuleNotFoundError: No module named 'photo-grid'
ModuleNotFoundError: No module named 'photo-grid'  Hi, My Python... 'photo-grid' How to remove the ModuleNotFoundError: No module named 'photo-grid' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'photo-import'
ModuleNotFoundError: No module named 'photo-import'  Hi, My Python... 'photo-import' How to remove the ModuleNotFoundError: No module named 'photo-import' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'photo-org'
ModuleNotFoundError: No module named 'photo-org'  Hi, My Python... 'photo-org' How to remove the ModuleNotFoundError: No module named 'photo... have to install padas library. You can install photo-org python with following
ModuleNotFoundError: No module named 'photo-sorter'
ModuleNotFoundError: No module named 'photo-sorter'  Hi, My Python... 'photo-sorter' How to remove the ModuleNotFoundError: No module named 'photo-sorter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'photo-uploader'
ModuleNotFoundError: No module named 'photo-uploader'  Hi, My... named 'photo-uploader' How to remove the ModuleNotFoundError: No module named 'photo-uploader' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'unach-photo'
ModuleNotFoundError: No module named 'unach-photo'  Hi, My Python... 'unach-photo' How to remove the ModuleNotFoundError: No module named 'unach-photo' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'django-photo-albums'
ModuleNotFoundError: No module named 'django-photo-albums'  Hi, My... named 'django-photo-albums' How to remove the ModuleNotFoundError: No module named 'django-photo-albums' error? Thanks   Hi
ModuleNotFoundError: No module named 'photo-namer-nautilus'
ModuleNotFoundError: No module named 'photo-namer-nautilus'  Hi...: No module named 'photo-namer-nautilus' How to remove the ModuleNotFoundError: No module named 'photo-namer-nautilus' error? Thanks   Hi
ModuleNotFoundError: No module named 'phyto-photo-utils'
ModuleNotFoundError: No module named 'phyto-photo-utils'  Hi, My... named 'phyto-photo-utils' How to remove the ModuleNotFoundError: No module named 'phyto-photo-utils' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'phyto-photo-utils'
ModuleNotFoundError: No module named 'phyto-photo-utils'  Hi, My... named 'phyto-photo-utils' How to remove the ModuleNotFoundError: No module named 'phyto-photo-utils' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'simple-photo-gallery'
ModuleNotFoundError: No module named 'simple-photo-gallery'  Hi...: No module named 'simple-photo-gallery' How to remove the ModuleNotFoundError: No module named 'simple-photo-gallery' error? Thanks   Hi
ModuleNotFoundError: No module named 'unach-photo-server'
ModuleNotFoundError: No module named 'unach-photo-server'  Hi, My... named 'unach-photo-server' How to remove the ModuleNotFoundError: No module named 'unach-photo-server' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'wagtail-photo-voter'
ModuleNotFoundError: No module named 'wagtail-photo-voter'  Hi, My... named 'wagtail-photo-voter' How to remove the ModuleNotFoundError: No module named 'wagtail-photo-voter' error? Thanks   Hi
How to create and use Facebook Shared Photo Albums?
Video Tutorial - How to create and use Facebook Shared Photo Albums? Facebook Shared Photo Albums is the feature added to the Facebook. It is very user... to use Facebook Shared Photo Albums?. We have also included a video tutorial

Ads