Friday, 15 July 2011

java - How to convert a multipart file to File? -



java - How to convert a multipart file to File? -

can 1 tell me best way convert multipart file (org.springframework.web.multipart.multipartfile) file (java.io.file) ?

in spring mvc web project i'm getting uploaded file multipart file.i have convert file(io) ,there fore can phone call image storing service(cloudinary).they take type (file).

i have done many searches failed.if knows standard way please allow me know? thnx

you can content of multipartfile using getbytes , can create file using fileoutputstream.

public file convert(multipartfile file) { file convfile = new file(file.getoriginalfilename()); convfile.createnewfile(); fileoutputstream fos = new fileoutputstream(convfile); fos.write(file.getbytes()); fos.close(); homecoming convfile; }

you can utilize method transferto

public file multiparttofile(multipartfile multipart) throws illegalstateexception, ioexception { file convfile = new file( multipart.getoriginalfilename()); multipart.transferto(convfile); homecoming convfile; }

java spring spring-mvc file-upload cloudinary

No comments:

Post a Comment