通过控制器调用静态方法时获得空指针异常,同时通过classname.method name

时间:2019-04-18 09:54:11

标签: java spring-boot nullpointerexception ibm-cloud attachment

公共静态无效createObject1(String bucketName,String file,String filePath){_cosClient.putObject(bucketName,bucket文件,new File(filePath)); System.out.println(“文件为” + _cosClient.listObjects(“知识共享”)));  }

@RequestMapping(值=“ / uploadFile”,方法= RequestMethod.POST)公共@ResponseBody字符串uploadFileHandler(@RequestParam(“ name”)字符串名称,@RequestParam(“ file”)MultipartFile文件){

if (!file.isEmpty()) {
    try {
        byte[] bytes = file.getBytes();
        File convFile = new File( file.getOriginalFilename());
       String fileName=  file.transferTo(convFile);

                File filePath= convFile.getAbsoluteFile();
                System.out.println("file are-"+filePath);
                String bucketName = "knowledge-sharing";
                objectStorage.createObject1("bucketName", "file", "filePath");
                System.out.println(filePath);

        return "You successfully uploaded file=" + name;
    } catch (Exception e) {
        System.err.println(e.getMessage());
        return "You failed to upload " + name + " => " + e.getMessage();
    }
} else {
    return "You failed to upload " + name
            + " because the file was empty.";
}

}

0 个答案:

没有答案