upload and download video

Ads
 

upload and download video

how to upload and download video in mysql databse using jsp? plz give me demo of this with table...

View Answers

September 23, 2011 at 4:33 PM

1)page.jsp

<%@ page language="java" %>
<Html>
<HEAD><TITLE>Display file upload form to the user</TITLE></HEAD>

<BODY>
<FORM ENCTYPE="multipart/form-data" ACTION="upload.jsp" METHOD=POST>
<br><br><br>
<center><table border="2" >
<tr><center><td colspan="2"><p align="center"><B>UPLOAD THE FILE</B><center></td></tr>
<tr><td><b>Choose the file To Upload:</b>
</td>
<td><INPUT NAME="file" TYPE="file"></td></tr>
<tr><td colspan="2">
<p align="right"><INPUT TYPE="submit" VALUE="Send File" ></p></td></tr>
<table>
</center>
</FORM>
</BODY>
</HTML>

2)upload.jsp

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

<%
String contentType = request.getContentType();
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while (totalBytesRead < formDataLength) {
byteRead = in.read(dataBytes, totalBytesRead,formDataLength);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
String saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
out.println(saveFile);
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
int pos;
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;

FileOutputStream fileOut = new FileOutputStream(saveFile);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();

%><Br><table border="2"><tr><td><b>You have successfully upload the file by the name of:</b>
<% out.println(saveFile);%></td></tr></table>
<%
Connection connection = null;
String connectionURL = "jdbc:mysql://192.168.10.112:3306/file";;;
ResultSet rs = null;
PreparedStatement psmnt = null;
FileInputStream fis;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "root");
File f = new File(saveFile);
psmnt = connection.prepareStatement("insert into file(file_data) values(?)");
fis = new FileInputStream(f);
psmnt.setBinaryStream(1, (InputStream)fis, (int)(f.length()));
int s = psmnt.executeUpdate();
if(s>0) {
System.out.println("Uploaded successfully !");
}
else {
System.out.println("unsucessfull to upload file.");
}
}
catch(Exception e){e.printStackTrace();}
}
%> 
<a href="download.jsp">Download File</a>

September 23, 2011 at 4:47 PM

3)download.jsp:

<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<%@page import="javax.servlet.*"%>
<%
ServletOutputStream output = response.getOutputStream();
String connectionURL = "jdbc:mysql://192.168.10.112:3306/file";;;;;
String Content=new String("");
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=DriverManager.getConnection(connectionURL,"root","root");
Statement st=con.createStatement();
ResultSet rst= st.executeQuery("select * from file");
if(rst.last())
{
Content=rst.getString("file_data");
}
con.close();
}catch(Exception e){
System.out.println("Exception caught"+e.getMessage());
}
byte requestBytes[] = Content.getBytes();
ByteArrayInputStream bis = new ByteArrayInputStream(requestBytes);
response.reset();
response.setContentType("mime/flv");
response.setHeader("Content-disposition","attachment; filename=" +"file.flv");
byte[] buf = new byte[1024];
int len;
while ((len = bis.read(buf)) > 0){
output.write(buf, 0, len);
}
bis.close();
response.getOutputStream().flush();
%>

October 6, 2011 at 11:20 AM

thnx..


June 27, 2012 at 6:24 AM

Hello can anyone give the table for database for the above coding....PLZ

Ads









Related Tutorials/Questions & Answers:
upload and download video
upload and download video  how to upload and download video in mysql...;Display file upload form to the user</TITLE></HEAD> <BODY> <FORM...;center><td colspan="2"><p align="center"><B>UPLOAD THE FILE<
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
Advertisements
upload video using php
upload video using php  How to upload a video on MYSQL Server using PHP Code..? Can any one provide me an example
Upload video app
Upload video app  Hi, How to create upload video application... should be able to take video from mobile phone b) User should be able upload the video on my server c) User should be able to save the video and then upload later
upload and download mp3
upload and download mp3   code of upload and download Mp3 file in mysql database using jsp and plz mention which data type used to store mp3 file in mysql database
Upload and Download multiple files
Upload and Download multiple files  Hello Sir/Madam, I need a simple code for upload and download multiple files(it may be image,doc... link: http://www.roseindia.net/jsp/file_upload/uploadingMultipleFiles.shtml
java/jsp code to download a video
java/jsp code to download a video  how can i download a video using jsp/servlet
Upload and Download Large files in jsp
Upload and Download Large files in jsp  I am not able to download large files (>200mb) from any server. I need a code to download and upload large files (atleast 4 gb) to a server using jsp page
Photo upload, Download
Photo upload, Download  Hi I am using NetBeans IDE for developing application for java(Swings). And i am using MySQL as backend database. My Problem is I have created JFrame form in NetBeans and i have inculded label in which i
ASP .Net Upload Video on youtube
ASP .Net Upload Video on youtube  Hi, I Naushad Ansari trying to upload video on youtube using my asp .net web application. I have read the documentation of youtube and I have created the application also but I am not getting
How to upload and download file in hadoop?
How to upload and download file in hadoop?  Hi, I am trying to learn to upload the file on the Hadoop HDFS and then download the same file for learning the process. How to upload and download file in hadoop? What
how to upload and download images using buttons in jsp?
how to upload and download images using buttons in jsp?  how to upload and download images using buttons in jsp
ModuleNotFoundError: No module named 'odoo8-addon-website-upload-video'
ModuleNotFoundError: No module named 'odoo8-addon-website-upload-video' ...: ModuleNotFoundError: No module named 'odoo8-addon-website-upload-video' How to remove the ModuleNotFoundError: No module named 'odoo8-addon-website-upload-video'
ModuleNotFoundError: No module named 'youtube-video-upload'
ModuleNotFoundError: No module named 'youtube-video-upload'  Hi...: No module named 'youtube-video-upload' How to remove the ModuleNotFoundError: No module named 'youtube-video-upload' error? Thanks   Hi
upload and download a file - Java Beginners
upload and download a file  how to upload a file into project folder in eclipse and how to download the same using jsp   Hi Friend, Try the following code: 1)page.jsp: Display file upload form to the user
how to upload and download images in java?
how to upload and download images in java?  what is the code....   Upload and Download images: 1)page.jsp: <%@ page language="java" %> <HTML> <HEAD><TITLE>Display file upload form
i want image upload and download useing STRUTS 1.2 version example..
i want image upload and download useing STRUTS 1.2 version example..  i am fresher of the developer..i want code for above title topic(i want image upload and download useing STRUTS 1.2 version example..)..plz send me code for my
Creat a folder, inside it upload and download files in jsp and mysql
Creat a folder, inside it upload and download files in jsp and mysql  Create one or more folder .inside it we can upload and download multiple files   Here is an application that will upload the file and save
JDBC Video Tutorial: How to download JDBC Driver for MySQL?
First thing to develop the JDBC program is to download the JDBC Driver... the MySQL database, so we have download the JDBC Driver for the MySQL... as on the Linux system. So, just download the Zip package. Visit the website
video
video   I need code for creating video chatting in a webpage.Can you send me the code related to that or API
UPLOAD
UPLOAD  how to upload image using html
Video Tutorial: How to download JDBC from MySQL?
How to download JDBC from MySQL? The video here teaches on how to download... file Here is the video tutorial of "How to download JDBC Driver... download process: Go to mysql.com from the search engine you are using
Download
Download JDK  How to Download the latest Version of JDK?   Download OST to PST converter from: http://www.osttopst.info
Download.
Download.  I need a swing program to download a file from the server
Video Tutorial: Features of eclipse Luna 4.4.2 - learn to download and install
Features of eclipse Luna 4.4.2 - learn to download and install In this video... to download and install it. Luna 4.4. is the latest  version. In this version... tools platform and memory analyzer. We download the eclipse luna 4.4 from here
video uploading using jsp
video uploading using jsp  how to upload a videos in web page using jsp   Hi, You can upload your video with the help of JSP file upload code. Once file is upload you can play using any video player. Get the code
File Download in jsp
File Download in jsp  file upload code is working can u plz provide me file download
How to download and install MySQL on Windows 10?
This video tutorial teaches you to install MySQL latest sever on Windows 10.... In this video tutorial we are going to learn how to install world's most... to the 32Bit System. I the video you will see the complete installation process
How to download ,install and use jQuery in the web application?
. Here is the video tutorial of "How to download, install and use jQuery?": In this video we will and learn how to download, install and use J Query...How to download, install and use jQuery in the web application? jQuery
Download Eclipse with Maven Plugin support
Plugin. In this video tutorial teaches you how to download, install and then create a web application using the Maven in the Eclipse IDE. Finally in this video we...Video tutorial of Downloading the Eclipse IDE having Maven Plugin support
video rating
video rating  Please send me the code for video rating using java

Ads