0
        HttpExchange exchange;
        OutputStream responseBody = null;
        try{
          File fileVal = new File(file);
          InputStream inVal = new FileInputStream(fileVal);
          exchange.sendResponseHeaders(HTTP_OK, fileVal.length());
          responseBody = exchange.getResponseBody();
          int read;
          byte[] buffer = new byte[4096];
          while ((readVal = inVal.read(buffer)) != -1){
            responseBody.write(buffer, 0, readVal);
          }
        } catch (FileNotFoundException e){
          //uh-oh, the file doesn't exist
        } catch (IOException e){
          //uh-oh, there was a problem reading the file or sending the response
        } finally {
          if (responseBody != null){
            responseBody.close();
          }
        }

I am tring to upload large video file as chunks .while doing the operation I am getting the following error.

groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.io.File(org.springframework.web.multipart.commons.CommonsMultipartFile)

any anyone guide me to solve this.

Süresh AK
  • 344
  • 3
  • 20

2 Answers2

0

The error message descripes the failure perfectly. There is no constructor for the class File that accept a parameter of the type org.springframework.web.multipart.commons.CommonsMultipartFile.

Try using the path to the file you want to open. For example:

String path = "/path/to/your/file.txt";
File fileVal = new File(path);

Alternatively you can use the getInputStream() method from CommonsMultipartFile.

InputStream inVal = file.getInputStream();
Henry Martens
  • 229
  • 1
  • 10
0
File fileVal = new File(file);

Here file is org.springframework.web.multipart.commons.CommonsMultipartFile type and you are trying to create File object by passing CommonsMultipartFile object in constructor and File class does not have constructor of CommonsMultipartFile type.

Check here for File Class Constructor

You Need to get Bytes from file object and create a java.io.File object.

Convert MultiPartFile into File

Pankaj Kanti
  • 93
  • 1
  • 5