我用spring-boot
应用创建了一个gradle
应用程序,该应用程序的端点是将图像上传到cloudinary
并返回cloudinary图像的URL。
以下是我的端点代码:
@PostMapping("/uploadPic")
public ResponseEntity<Object> upload(@RequestParam("file") MultipartFile multipartFile){
String cloudinaryImgURL=null;
try {
File fileDir = new File("rowFiles");
if (! fileDir.exists()){
fileDir.mkdir();
}
String fileName=multipartFile.getOriginalFilename();
File physicalFile=new File(multipartFile.getOriginalFilename());
FileOutputStream fout=new FileOutputStream(fileDir.getName()+"/"+physicalFile);
fout.write(multipartFile.getBytes());
fout.close();
File toUpload = new File("rowFiles/"+fileName);
Cloudinary cloudinary = new Cloudinary();
System.out.println("API Key:"+cloudinary.config.apiKey);
Map params = ObjectUtils.asMap("public_id", "SRWRestImageBase/"+fileName);
Map uploadResult = cloudinary.uploader().upload(toUpload, params);
toUpload.delete();
System.out.println("==============>>"+uploadResult.get("url"));
cloudinaryImgURL=uploadResult.get("url").toString();
} catch (Exception e) {
System.out.println("upload:"+e.getMessage());
}
return new ResponseEntity<Object>("File uploaded successfully:"+cloudinaryImgURL,HttpStatus.OK);
}
我已经在本地计算机上的环境变量中使用CLOUDINARY_URL
变量设置了cloudinary帐户凭据。
该端点可以在我的本地计算机上正常工作,并可以上传通过postman
发送的图像。
我在heroku
上部署了相同的应用程序,并在我的heroku应用程序CLOUDINARY_URL
中设置了配置变量config variables
。但是,当我通过邮递员到达该网址的端点时,它给出了以下heroku错误日志:
2018-08-22T10:55:47.637562+00:00 app[web.1]: the exception is: Can't find Cloudinary platform adapter [com.cloudinary.android.UploaderStrategy,com.cloudinary.http42.UploaderStrategy,com.cloudinary.http43.UploaderStrategy,com.cloudinary.http44.UploaderStrategy]
2018-08-22T10:55:47.637564+00:00 app[web.1]: At:upload
2018-08-22T10:55:47.637566+00:00 app[web.1]: with arguments: [org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile@410b9d11]
2018-08-22T10:55:47.638002+00:00 app[web.1]: and the full toString: ResponseEntity com.sware.SpringBoot_JPA_MySQL_Gradle_Project.rest_controllers.UserRestController.upload(MultipartFile)
2018-08-22T10:55:47.641005+00:00 app[web.1]: 2018-08-22 10:55:47.640 ERROR 4 --- [io-47964-exec-9] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.UnknownError: Can't find Cloudinary platform adapter [com.cloudinary.android.UploaderStrategy,com.cloudinary.http42.UploaderStrategy,com.cloudinary.http43.UploaderStrategy,com.cloudinary.http44.UploaderStrategy]] with root cause
2018-08-22T10:55:47.641008+00:00 app[web.1]:
2018-08-22T10:55:47.641010+00:00 app[web.1]: java.lang.UnknownError: Can't find Cloudinary platform adapter [com.cloudinary.android.UploaderStrategy,com.cloudinary.http42.UploaderStrategy,com.cloudinary.http43.UploaderStrategy,com.cloudinary.http44.UploaderStrategy]
2018-08-22T10:55:47.641012+00:00 app[web.1]: at com.cloudinary.Cloudinary.loadStrategies(Cloudinary.java:73) ~[cloudinary-core-1.19.0.jar!/:na]
2018-08-22T10:55:47.641014+00:00 app[web.1]: at com.cloudinary.Cloudinary.<init>(Cloudinary.java:99) ~[cloudinary-core-1.19.0.jar!/:na]
2018-08-22T10:55:47.641016+00:00 app[web.1]: at com.sware.SpringBoot_JPA_MySQL_Gradle_Project.rest_controllers.UserRestController.upload(UserRestController.java:55) ~[classes!/:na]
2018-08-22T10:55:47.641018+00:00 app[web.1]: at com.sware.SpringBoot_JPA_MySQL_Gradle_Project.rest_controllers.UserRestController$$FastClassBySpringCGLIB$$e380b026.invoke(<generated>) ~[classes!/:na]
2018-08-22T10:55:47.641019+00:00 app[web.1]: at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.11.RELEASE.jar!/:4.3.11.RELEASE]
2018-08-22T10:55:47.641021+00:00
经过一番研究,我认为我必须在heroku上的应用程序中添加cloudinary-add-on
,所以我试图在heroku的资源选项卡上添加免费版本,但这是在询问我我的credit card
详细信息我选择了免费版本。
所以任何人都可以指导我如何解决这个问题。我不想为cloudinary-add-on付费,因为我没有将这个应用程序开发为商业用途。或任何解决此异常的方法。
在使用此功能方面苦苦挣扎,在成功部署之后,我将尝试撰写有关此完整过程的文章。 预先感谢。