Daniel,

While others have provide you with alternative suggestions to pursue, I had one additional thought. If all you are interested in sending is the file name, you should be able to extract that from the HTTP PUT request itself - unless of course you want the file name to "put" to be different from the actual file name that you use in the "PUT" request.

I could imagine, for example, that you want to send a file name like "c:\program files\my application\myfilename.txt", and you cannot put that as the path in a PUT request (although you can URL encode it, Tomcat and other servlet containers will reject it). If all you are doing, however, is getting the name "myfilename.txt", then using a PUT request like "/myserlvetcontext/myfilename.txt" ought to be sufficient. I hope you realize that by allowing the remote client to specify an arbitrary location on the local hard-drive to save a file, you have introduced huge security risk? By doing so, you enable a remote client to overwrite any file locally, and take over your system. In fact, if you turn on security in your servlet container (Tomcat?), it should start preventing you from creating the files that you're creating, unless you are putting the files in the temporary folder ("work") explicitly allowed by the Servlet API. See the servlet API for more details.

Daniel Walsh wrote:

I'm trying to use HttpClient's PutMethod to transfer a file from my
client application to the associated Servlet. There isn't actually a UI
for this application, in the end I want to automate the process. I'm
not sure if there is a better way of doing a file upload such as this,
but what I've been trying to do uses a couple of requests to the Servlet
to implement the entire file transfer:

[snip]

ServletInputStream in = req.getInputStream();
byte[] reqContent;
int contentLength = 0;
while(in.read() != -1)
++contentLength;
reqContent = new byte[contentLength];

in.read(reqContent);

The above code would appear to be the reason for your "blank file" on the server, in any case. An InputStream is a one-shot thing. You get to read it once. Your second attempt to read above ("in.read(reqContent);" )will not actually read anything.

-Eric Johnson



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



Reply via email to