Hello,

I facing the while reading and writing binary files to
Apache Tomcat/4.1.24 web server .

I will be very kind if any body from your side help me
out.

I had which upload file to server using . This same
being used by c++ application also . As the take any
type of file from user and call for upload to server,
As this works very well with non-binary files, but
when I pass binary files like & compress files gets
when send to server by .
About the it takes from database create connection
with that and then pass this file as string object to
and in last upload file to tomcat 3.1 web server. This
same is used by VB application to upload files from
there application and it works fine.

With best ,

Sun Certified Programmer.

The (c++) is as follows
======================================
int32 (char *, char *)// {

=NULL, =NULL;

= ();
if(==NULL)
return 0;

=();
if(==NULL)
return 0;

if(!("","","(//String;//", ,))
return 0;

();
();

return 1;
}
================================

And which upload to server is follows

===============================
public static void (String , String )
throws {

= new ();
= null;
= new ();
.(.ERROR_DEBUG);
try {
= .();
} catch (Exception ) {
Logger.error(Logger.SERVER_LOG, "Cannot connect to
server");
throw new ();
}
if ( == null) {
.(._NOT_DEFINED);
throw ; }
String = ._();
in = null;
String data = null;
byte[] ;
;
try {
= new ( + File.separator + , "");
= new byte[(int) .length()];
.();
data = new String();
} catch (Exception ) {
Logger.error(Logger.SERVER_LOG, "local file not
found");
.(._FILE_NOT_FOUND_LOCAL);
throw ;
}
URL = null;
con = null;
try {
= new URL();
con = .();
con.(true);
con.(true);
con.(false);
con.(false);
con.("Content-Type",
"/form-=------------------------12012133613061");
System.out.( + File.separator + );
out = new (con.());
out.print("--------------------------12012133613061" +
'\n');
out.print("Accept: */*"+'\n');
out.print("Content-Disposition: form-data;
name=\"Filename\"; filename=\""
+ + File.separator + + "\"" + '\n');
out.print("Content-Type: /form-data" + '\n' + '\n');
out.print(data + '\n' + '\n');
out.print("--------------------------12012133613061");
out.close();

} catch (Exception ) {
Logger.error(Logger.SERVER_LOG, "Cannot connect to
server");
.(._CANNOT_BE_REACHED);
throw ;
}
= null;
try {
= con.();
} catch (Exception 2) {
return;
}
try {
int length = 0, read = 0;
byte[] = new byte[(int) .length()];
= new ();

while ((read = .read()) != -1)
.append(new String());

System.out.();
con = null;
if ( == null)
return;
if (.().("FILE_UPLOAD_FAILED") > 0) {
.(._FILE_UPLOAD_FAILED);
throw ; }
} catch (Exception 2) {
return;
}
}
===============================

which upload the file to tomcat web server
==========================================
protected void ( request, response)
throws Exception, {

String filename = request.("filename");
if (filename != null && filename.trim().length() != 0)
= true;
else
= false;
String path = this.().("");
request.().("FILE_UPLOAD_RESULT");
if (!) {

parser = null;
try {
parser =
new (request, request.(), false, false, null);
} catch (Exception e) {
request.().("FILE_UPLOAD_RESULT",
"FILE_UPLOAD_FAILED");
return;
}
Part part = parser.();
File file = null;
while (part != null) {
if (part.()) {
file = new File(path + .().());
(() part).(file);
}
part = parser.();
}
request.().("FILE_UPLOAD_RESULT",
"FILE_UPLOAD_SUCCESSFUL");
} else {
if ((filename))
request.().("FILE_UPLOAD_RESULT", "FILE_EXISTS");
else
request.().("FILE_UPLOAD_RESULT", "FILE_NOT_EXISTS");
}
}
==========================================

/** About
* A utility class to handle <code>/form-data</code>
requests,
* the kind of requests that support file uploads. This
class uses a
* "pull" model where the reading of incoming files and
parameters is
* controlled by the client code, which allows incoming
files to be stored
* into any <code></code>.
**/

/** About Part
* A <code>Part</code> is an abstract upload part which
represents an
* <code>INPUT</code> form element in a
<code>/form-data</code> form
* submission.
**/

/** About
* A <code></code> is an upload part which represents a
* <code>INPUT TYPE="file"</code> form parameter. Note
that because file
* upload data arrives via a single , each 's contents
* must be read before moving onto the next part. Don't
try to store a
* object for later processing because by then their
content will
* have been passed by.
**/

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to