Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 3rd, 2006, 05:45 AM
Authorized User
 
Join Date: Jan 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Store and Retrieve Images in SQL Database

Hi everyone, I was trying to store and retrieve images to sqlserver. I did that in 1 tier. I convert them to binary and write them. But i face problem when i trying to put them in 3 tier (Data , Logic, Presentation) Kindly advise where I can find help or is there tutorial that teaches store and retrieve images to sql database in 3 tier. thanks in advance...

 
Old February 6th, 2006, 02:54 AM
Registered User
 
Join Date: Dec 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to munnu Send a message via Yahoo to munnu
Default

Hi derekl,

Nice.. when u say that u could do with 1 tier then i don't think u shud be having a problem with 3 tier.

Anyways..please post the error message also, so that to give the solution.


Tackle the tough time to show the Talent
 
Old December 19th, 2007, 02:50 AM
Registered User
 
Join Date: Dec 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

:(

 
Old December 19th, 2007, 02:51 AM
Registered User
 
Join Date: Dec 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<%

response.setContentType("text/html");
response.setHeader("Cache-control","no-cache");

String err = "";
String lastFileName = "";
String contentType = request.getContentType();
String boundary = "";

final int BOUNDARY_WORD_SIZE = "boundary=".length();

System.out.println("contentType --> "+contentType);
System.out.println("BOUNDARY_WORD_SIZE --> "+BOUNDARY_WORD_SIZE);

if(contentType == null || !contentType.startsWith("multipart/form-data"))
{
err = "Ilegal ENCTYPE : must be multipart/form-data\n";
err += "ENCTYPE set = " + contentType;
}
else
{
boundary = contentType.substring(contentType.indexOf("boundar y=") + BOUNDARY_WORD_SIZE);

System.out.println("boundary --> "+boundary);

boundary = "--" + boundary;
try
{
ServletInputStream sis = request.getInputStream();

byte[] b = new byte[1024];
int x=0;
int state=0;
String name=null,fileName=null,contentType2=null;
java.io.FileOutputStream buffer = null;

while((x=sis.readLine(b,0,1024))>-1)
{
System.out.println("************ x ********** "+x);

String s = new String(b,0,x);
System.out.println("************ s ********** \n"+s);

if(s.startsWith(boundary))
{
state = 0;
System.out.println("name="+name);
System.out.println("filename="+fileName);
name = null;
contentType2 = null;
fileName = null;
}
else if(s.startsWith("Content-Disposition") && state==0)
{
System.out.println("-- 1 --");
state = 1;
System.out.println("s.indexOf(filename=) --> "+s.indexOf("filename="));
if(s.indexOf("filename=") == -1)
{
name = s.substring(s.indexOf("name=") + "name=".length(),s.length()-2);
System.out.println("after name substring 1 "+name);
}
else
{
name = s.substring(s.indexOf("name=") + "name=".length(),s.lastIndexOf(";"));
System.out.println("after name substring 2 "+name);

fileName = s.substring(s.indexOf("filename=") + "filename=".length(),s.length()-2);
System.out.println("fileName --> "+fileName);

//String fileName1 = s.substring(s.indexOf("filename=") + "filename=".length(),s.length());
//System.out.println("fileName1 -->"+fileName1);


if(fileName.equals("\"\""))
{
fileName = null;
}
else
{
String userAgent = request.getHeader("User-Agent");
System.out.println("userAgent --> "+userAgent);
String userSeparator="/"; // default
if (userAgent.indexOf("Windows")!=-1)
{
System.out.println("test --> "+"
");
userSeparator="
";
}
if (userAgent.indexOf("Linux")!=-1)
{
userSeparator="/";
}
System.out.println("userSeparator "+userSeparator);
System.out.println("fileName before inserting userSeparators "+fileName);
fileName = fileName.substring(fileName.lastIndexOf(userSepara tor)+1,fileName.length()-1);

System.out.println("fileName after userSeparators "+fileName);

if(fileName.startsWith( "\""))
{
fileName = fileName.substring( 1);
}
}
}
name = name.substring(1,name.length()-1);
System.out.println("name 2 --> "+name);
System.out.println("final file name "+fileName);

if (name.equals("file"))
{
if (buffer!=null)
buffer.close();
lastFileName = fileName;
buffer = new java.io.FileOutputStream("/Documents and Settings/sunil/Desktop/images/"+fileName);
}
}
else if(s.startsWith("Content-Type") && state==1)
{
System.out.println("-- 2 --");
state = 2;
contentType2 = s.substring(s.indexOf(":")+2,s.length()-2);
System.out.println("contentType2 --> "+contentType2);
}
else if(s.equals("\r\n") && state != 3)
{
System.out.println("-- 3 --");
state = 3;
}
else
{
System.out.println("-- 4 --");

if (name.equals("file"))
{

System.out.println("Final x :: "+x);
buffer.write(b,0,x);

}
}
} // while closing
sis.close();
buffer.close();
}catch(java.io.IOException e)
{
err = e.toString();
}
}
boolean ok = err.equals("");
if(!ok)
{
out.println(err);
}
else
{
%>
<SCRIPT language="javascript">
history.back(1);
alert('Uploaded <%=lastFileName%>');
window.location.reload(false);
</SCRIPT>
<%
}
out.println("done");
%>


</BODY>
</HTML>


 
Old December 19th, 2007, 03:16 AM
Registered User
 
Join Date: Dec 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

:)






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to store image in sql server database Debmit_das ASP.NET 2.0 Basics 5 March 21st, 2008 05:31 AM
how to store file in sql server 2000 database vivekkumar_23 SQL Server 2000 1 February 27th, 2006 10:41 PM
How to store image in oracle database and retrieve y.suresh JSP Basics 1 February 28th, 2005 07:01 AM
Store Pictures on SQL Database fmo_82 C# 1 February 17th, 2005 11:47 PM
Retrieve and store the images from server URL ccc_storage Classic ASP Professional 13 August 19th, 2004 07:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.