Transferring and saving MultipartFile instance

194 Views Asked by At

I have the following method, with the simple aim to store the contents of a given MultipartFile instance under a specified directory:

private void saveOnDisk(final String clientProductId, final MultipartFile image, final String parentDirectoryPath, final String fileSeparator) throws IOException
    {
        final File imageFile = new File(parentDirectoryPath + fileSeparator + clientProductId + image.getOriginalFilename());
        image.transferTo(imageFile);
        OutputStream out = new FileOutputStream(imageFile);
        out. //... ? How do we proceed? OutputStream::write() requires a byte array or int as parameter
    }

For what it might be worth, the MultipartFile instance is going to contain an image file which I receive on a REST API I'm building.

I've checked some SO posts such as this and this but this problem is not quite touched: I'm effectively looking to create an entirely new image file and store it on a specified location on disk: the method write() of OutputStream, given that it requires byte[] or int params, doesn't seem to be fitting my use case. Any ideas?

0

There are 0 best solutions below