On Mar 3, 2009, at 6:32 AM, beanor wrote:
>
> hi Paul:
>
> First, I'm very thank you for your help. Your code is working
> nice.But I
> have got another problem, follow is very code:
>
> @Path("form-data")
> @Consumes(MediaType.MULTIPART_FORM_DATA)
> @POST
> public void uploadUrlFormData(
> @FormParam("file") InputStream file,
> @FormParam("file") FormDataContentDisposition cd
> ) throws IOException {
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> int read = 0;
> byte[] buf = new byte[4096];
> while ((read = file.read(buf)) != -1) {
> baos.write(buf, 0, read);
> }
> byte[] byteArr = baos.toByteArray();
> File f = new File("c:/a.rar");
> FileOutputStream fos = new FileOutputStream(f);
> BufferedOutputStream bof = new BufferedOutputStream(fos);
> bof.write(byteArr);
> bof.close();
> bof.flush();
> fos.close();
> baos.close();
> file.close();
> System.out.println("form-data file name: " + new
> String(cd.getFileName().getBytes(),"utf-8"));
> }
Why don't you write directly to the buffered output stream wrapper of
the file output stream? then you do not need to create an in-memory
copy of all the bytes.
>
>
>
> new String(cd.getFileName().getBytes(),"utf-8")
>
> I want get the uploading file name, But this will get a full path,
The client is sending the full path as the "filename" parameter
property. You can verify that with a logging filter. Jersey will not
modify that parameter so it is up to you to obtain the last path
segment of that value.
I think you can do this:
String s = new File(cd.getFileName()).getName();
> And
> another problem is that the chinese char is not deal, I had got a bad
> string.
>
Hmm.... Jersey uses the Java Mail API and all it obtains is String
values, and performs no unicode operations.
Would it be possible to zip up a simple maven project with a
reproducible test case so i can investigate further?
Paul.