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 call image storing service(cloudinary).they take type (file).
i have done many searches failed.if knows standard way please let me know? thnx
you can content of multipartfile
using getbytes
method , can create instance of file
class using fileoutputstream
class.
public file convert(multipartfile file) { file convfile = new file(file.getoriginalfilename()); convfile.createnewfile(); fileoutputstream fos = new fileoutputstream(convfile); fos.write(file.getbytes()); fos.close(); return convfile; }
you can use transferto method:
public file multiparttofile(multipartfile multipart) throws illegalstateexception, ioexception { file convfile = new file( multipart.getoriginalfilename()); multipart.transferto(convfile); return convfile; }
https://ngdeveloper.com/how-to-convert-multipart-file-to-file-in-spring-boot/
ReplyDelete