Reputation: 359
How can i convert an object of type java.nio.ByteBuffer to spring MultipartFile object .
thanks
Upvotes: 2
Views: 930
Reputation: 15223
ByteBuffer provides an array method (with signature public final byte[] array()
) which can be used to return a byte[]
.
This can be provided as an input to the constructor of MockMultipartFile (with signature public MockMultipartFile(String name, @Nullable byte[] content)
), which implements MultipartFile, as below and create a MultipartFile
object
ByteBuffer buffer = ByteBuffer.allocate(1); //any kind of ByteBuffer initialization that you have
byte[] byteArray = buffer.array();
MultipartFile multipartFile = new MockMultipartFile("fileName", byteArray);
Upvotes: 2