I am receiving image in the form of BASE64 encoded String(encodedBytes) and use following approach to decode into byte[] at server side.
BASE64Decoder decoder = new BASE64Decoder();
byte[] decodedBytes = decoder.decodeBuffer(encodedBytes);
Now i want to convert it into MultipartFile using this byte obtained above?
Is there any way to convert byte[] to org.springframework.web.multipart.MultipartFile??
This answer has already been answered above. Recently i was working on the requirement to convert byte array object to multipartfile object. There are two ways to achieve this.
Approach 1:
Use the default CommonsMultipartFile where you to use the FileDiskItem object to create it. Example:
Use the default CommonsMultipartFile where you to use the FileDiskItem object to create it. Example:
Approach 2:
Create your own custom multipart file object and convert the byte array to multipartfile.
This how you can use above CustomMultipartFile object.
This will create the required PDF and store that into
Thanks.
org.springframework.web.multipart.MultipartFile
is an interface so firstly you are going to need to work with an implementation of this interface.The only implementation that I can see for that interface that you can use out-of-the-box is
org.springframework.web.multipart.commons.CommonsMultipartFile
. The API for that implementation can be found hereAlternatively as
org.springframework.web.multipart.MultipartFile
is an interface, you could provide your own implementation and simply wrap your byte array. As a trivial example: