FTP图片上传OSS图片处理失败
Closed this issue · 3 comments
- 版本为2.1.0
- 使用框架为springboot 2.7.6
- 代码如下
FTPFile latestImageFile = latestImageFileOptional.get();
// 读取FTP文件内容到ByteArrayOutputStream
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (InputStream ftpInputStream = ftpClient.retrieveFileStream(latestImageFile.getName())) {
byte[] buffer = new byte[1024];
int length;
while ((length = ftpInputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
}
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
return fileStorageService.of(inputStream)
.image(img -> img.size(1920, 1080))
.setPlatform("aliyun-oss-1")
.upload();
下面是报错内容:org.dromara.x.file.storage.core.exception.FileStorageRuntimeException: 图片处理失败!
at org.dromara.x.file.storage.core.UploadPretreatment.image(UploadPretreatment.java:548) ~[x-file-storage-core-2.1.0.jar!/:na]
at org.dromara.x.file.storage.core.upload.UploadPretreatment.image(UploadPretreatment.java:680) ~[x-file-storage-core-2.1.0.jar!/:na]
at org.dromara.x.file.storage.core.upload.UploadPretreatment.image(UploadPretreatment.java:26) ~[x-file-storage-core-2.1.0.jar!/:na]
at org.dromara.x.file.storage.core.UploadPretreatment.image(UploadPretreatment.java:564) ~[x-file-storage-core-2.1.0.jar!/:na]
at org.dromara.x.file.storage.core.upload.UploadPretreatment.image(UploadPretreatment.java:696) ~[x-file-storage-core-2.1.0.jar!/:na]
at com.springboot.task.PushDataTask.fetchLatestImageFromFTP(PushDataTask.java:333) ~[classes!/:na]
at com.springboot.task.PushDataTask.fetchAndSaveLatestImage(PushDataTask.java:363) ~[classes!/:na]
at com.springboot.task.PushDataTask.pushImages(PushDataTask.java:101) ~[classes!/:na]
at com.springboot.task.PushDataTask$$FastClassBySpringCGLIB$$4984ef10.invoke() ~[classes!/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.24.jar!/:5.3.24]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.24.jar!/:5.3.24]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.24.jar!/:5.3.24]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.24.jar!/:5.3.24]
at org.springframework.aop.interceptor.AsyncExecutionInterceptor.lambda$invoke$0(AsyncExecutionInterceptor.java:115) ~[spring-aop-5.3.24.jar!/:5.3.24]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_212]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_212]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_212]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_212]
Caused by: net.coobird.thumbnailator.tasks.UnsupportedFormatException: No suitable ImageReader found for source data.
at net.coobird.thumbnailator.tasks.io.InputStreamImageSource.read(Unknown Source) ~[thumbnailator-0.4.20.jar!/:0.4.20]
at net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask.read(Unknown Source) ~[thumbnailator-0.4.20.jar!/:0.4.20]
at net.coobird.thumbnailator.Thumbnailator.createThumbnail(Unknown Source) ~[thumbnailator-0.4.20.jar!/:0.4.20]
at net.coobird.thumbnailator.Thumbnails$Builder.toOutputStream(Unknown Source) ~[thumbnailator-0.4.20.jar!/:0.4.20]
at org.dromara.x.file.storage.core.UploadPretreatment.image(UploadPretreatment.java:544) ~[x-file-storage-core-2.1.0.jar!/:na]
... 17 common frames omitted
你先把ftp中的文件下载到本地看看,是不是一个正常图片
实际上 of 可以直接传入 InputStream 进行上传
fileStorageService.of(ftpClient.retrieveFileStream(latestImageFile.getName()))
谢谢大佬,按照fileStorageService.of(ftpClient.retrieveFileStream(latestImageFile.getName()))方法可以正常使用了.