0

I want to extract all the files in my .tar.gz MultipartFile and add the files to a List

@RequestMapping(value="/importFile", produces="application/json", method=RequestMethod.POST)
    @ResponseBody
    public ca.alea.cam.api.model.Response importFile(@RequestBody MultipartFile file) throws ContentRepositoryDaoException, Exception {
        List<File> fileList = new ArrayList<File>();
        
        InputStream in = file.getInputStream();
        GzipCompressorInputStream gzipIn = new GzipCompressorInputStream(in);
        TarArchiveInputStream tarIn = new TarArchiveInputStream(gzipIn);
        TarArchiveEntry entry = tarIn.getNextTarEntry();
        
        while (entry != null) {
            // untar and add each file in MultipartFile to fileList
            // fileList.add()...
            //fileList.add(entry.getFile()) -> This returns a null, as expected from https://commons.apache.org/proper/commons-compress/apidocs/org/apache/commons/compress/archivers/tar/TarArchiveEntry.html#getFile--
        }

Thanks

user1971376
  • 93
  • 1
  • 4
  • 10
  • Use `entry.getName()` instead of getFile. – VGR Aug 09 '22 at 21:31
  • Hi, thanks but doesnt `.getName()` return a String? How would I save that as a File and add it to `fileList`? Thanks – user1971376 Aug 09 '22 at 22:41
  • You know that callers of your REST API who are running on other computers will not be able to read those files, right? A `File` object is just a file path; it does not contain the file contents. – VGR Aug 10 '22 at 12:56

0 Answers0