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/









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. (adsbygoogle = window.adsbygoogle || []).push... I'll get path of the photo in local machine in variable "path" (I dont know whether
Advertisements
PHOTO UPLOAD AND DISPLAY - Struts
PHOTO UPLOAD AND DISPLAY  Hi, This is chandra Mohan. I want some help urgently from your side. My problem is I want to upload the photos and display photos usin Struts technology. Please give me some suggestion to me
Upload Photo to Server
Upload Photo to Server  Hi I am using NetBeans IDE for developing... i am loading photo. (adsbygoogle = window.adsbygoogle || []).push...()); } } Here I'll get path of the photo in local machine in variable "path" . My question
Upload photo - Java Beginners
Upload photo  Morning, Can you tell me coding how to upload photo. First, i want to browse the photo from my direktory(*.jpg, *.bmp *.gif), then i click this photo and view in my JFrameForm then i have a button to save
Photo Upload - JSP-Servlet
Photo Upload  Dear Sir, I want some help you i.e code for image upload and download using Servle/jsp. Thanks&Regards, VijayaBabu.M ...(); %> You have successfully upload the file by the name
how to upload photo - Java Beginners
how to upload photo  dear sir, I has a case like that, first i have jlabel. i want to view data like photo/picture to jlabel. then i have a button...{ public static void main(String[] args){ JFrame frame = new JFrame("Upload Image
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
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
photo gallery - Java Beginners
photo gallery  Iam uploading images in the serverusing uploading... it dynamically with out giving the path. please help  Hi friend, For upload image visit to : http://www.roseindia.net/jsp/file_upload/employee_upload
UPLOAD
UPLOAD  how to upload image using html
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 '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
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
View Photo From Db MySql
View Photo From Db MySql  Good Morning Sir, Please help me, I make a small code but i have a error. I want to make viewer photo from database MySql into my project in netbeans. this is my code : try
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
image upload in webapp/upload folder
image upload in webapp/upload folder  sir i want to store upload image in my project directory WebApp/Upload_image/ pls send the jsp servlet code when i upload the image one error found "system cannot found the specified path
upload video
upload video  hi sir i want to code of upload and download video in mysql database using jsp... and plz give advice which data type is used to store video in table
upload an image
upload an image  Hello, i would like to upload an image to the database. how can i do it? what field type should i set in the database? thanx
upload image
upload image  I want to upload image from user using Jdbc connectivity and servlets and Html pages. I tried code but getting error using multi parts,so please send the code
File Upload
File Upload  when i execute the image upload to mysql database it shows an exception that file path cannot be found
images upload
images upload  I use netbeans IDE 6.8 How i upload any image from any folder to web page
how to upload multiple files in jsp and saving the path in database and the file in folder
how to upload multiple files in jsp and saving the path in database and the file in folder  how to upload multiple files in jsp and saving the path in database and the file in folder I have created a form for the upload of files
ModuleNotFoundError: No module named 'photo-geotag-restful-api-client-library'
ModuleNotFoundError: No module named 'photo-geotag-restful-api-client-library...: ModuleNotFoundError: No module named 'photo-geotag-restful-api-client-library' How to remove the ModuleNotFoundError: No module named 'photo-geotag-restful-api
HTML Upload
HTML Upload  Hi, I want to upload a word / excel document using the html code (web interface)need to get displayed on another webpage. Please let me the coding to display on another webpage using
upload pdf
upload pdf   i want to dispal content of pdf fil and stored into database in human readable form using php . how can i do
upload - JSP-Servlet
Upload jar file  What is the steps to upload Jar file in Java
File Upload in Struts.
File Upload in Struts.  How to do File Upload in Struts
upload image data
upload image data  Hii Upload image dat in csv files