java - Converting File to MultiPartFile -


is there way convert file object multipartfile? can send object methods accept objects of multipartfile interface?

file myfile = new file("/path/to/the/file.txt")  multipartfile ....?  def (multipartfile file) {   def = new bufferedinputstream(file.getinputstream())   //do interesting stream } 

mockmultipartfile exists purpose. in snippet if file path known, below code works me.

import java.nio.file.files; import java.nio.file.path; import java.nio.file.paths; import org.springframework.mock.web.mockmultipartfile;  path path = paths.get("/path/to/the/file.txt"); string name = "file.txt"; string originalfilename = "file.txt"; string contenttype = "text/plain"; byte[] content = null; try {     content = files.readallbytes(path); } catch (final ioexception e) { } multipartfile result = new mockmultipartfile(name,                      originalfilename, contenttype, content); 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -