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
Post a Comment