[jcifs] Need help loading a file...please
Laura McCord
mccordl at southwestern.edu
Fri Jun 29 03:04:41 GMT 2007
Awesome!!! Thanks so much to you and Michael Allen for helping me. I can finally sleep better tonight.
Quoting "Frode E. Moe" <frode at CoreTrek.no>:
> On Thu, Jun 28, 2007 at 08:23:54 -0500, Laura McCord wrote:
>> Well, I think I am getting a little but closer. It at least is giving me
>> the total number of bytes transferred. So, with this said perhaps it is
>> actually getting the image. However, I still can't get the image to
>> actually display.
>>
>> My logs indicate:
>> ######################
>> 172176 bytes transfered in 0 seconds at 172Kbytes/sec
>>
>> The way I am testing it is by using a jsp file:
>> <img src="image?file=Image002/20060725/273251.jpg" />
>>
>>
>> protected void doGet(HttpServletRequest req,HttpServletResponse res)
>> throws ServletException, IOException
>> {
>> // Get file name from request.
>> String imageFileName = req.getParameter("file");
>> // Check if file name is supplied to the request.
>> if (imageFileName == null) {
>> return;
>> }
>> System.err.println(imageFileName);
>> // Prepare streams.
>>
>> // Open image file.
>> Config.setProperty("jcifs.netbios.wins", "ipaddress");
>> Config.setProperty("jcifs.smb.client.domain", "domain");
>> Config.setProperty("jcifs.smb.client.username", "user");
>> Config.setProperty("jcifs.smb.client.password", "secret");
>>
>> SmbFile f = new SmbFile("smb://ipaddress/idworks/" + imageFileName);
>> SmbFileInputStream in = new SmbFileInputStream( f );
>> res.setContentType("image/jpeg");
>> FileOutputStream out = new FileOutputStream( f.getName() );
>>
>> long t0 = System.currentTimeMillis();
>>
>> byte[] b = new byte[8192];
>> int n, tot = 0;
>> long t1 = t0;
>> while(( n = in.read( b )) > 0 ) {
>> out.write( b, 0, n );
>> tot += n;
>> System.err.print( '#' );
>> }
>>
>> long t = System.currentTimeMillis() - t0;
>>
>> System.err.println();
>> System.err.println( tot + " bytes transfered in " + ( t / 1000 ) +
>> " seconds at " + (( tot / 1000 ) / Math.max( 1, ( t / 1000 ))) +
>> "Kbytes/sec" );
>> in.close();
>> out.close();
>> }
>
> Of course nothing is shown on the browser, you're not writing any data
> to it. Try replacing the "FileOutputStream out...." with
> "OutputStream out = res.getOutputStream()".
>
> - Frode
>
More information about the jcifs
mailing list