|
35 | 35 | import javax.imageio.stream.ImageOutputStream;
|
36 | 36 |
|
37 | 37 | import edu.harvard.iq.dataverse.DataFile;
|
| 38 | +import edu.harvard.iq.dataverse.DataFileServiceBean; |
38 | 39 | import edu.harvard.iq.dataverse.util.FileUtil;
|
39 | 40 | import edu.harvard.iq.dataverse.util.SystemConfig;
|
40 | 41 | import java.io.ByteArrayOutputStream;
|
41 |
| -import java.io.FileNotFoundException; |
42 | 42 | import java.io.FileOutputStream;
|
43 | 43 | import java.io.OutputStream;
|
44 | 44 | import java.nio.channels.Channel;
|
45 | 45 | import java.nio.channels.Channels;
|
46 |
| -import java.nio.channels.FileChannel; |
47 | 46 | import java.nio.channels.ReadableByteChannel;
|
48 | 47 | import java.nio.channels.WritableByteChannel;
|
49 | 48 | import java.nio.file.Path;
|
50 | 49 | import java.nio.file.Paths;
|
51 |
| -import java.util.logging.Level; |
52 | 50 | import java.util.logging.Logger;
|
| 51 | + |
| 52 | +import jakarta.enterprise.inject.spi.CDI; |
53 | 53 | import org.apache.commons.io.IOUtils;
|
54 | 54 | //import org.primefaces.util.Base64;
|
55 | 55 | import java.util.Base64;
|
@@ -172,15 +172,26 @@ public static InputStreamIO getImageThumbnailAsInputStream(StorageIO<DataFile> s
|
172 | 172 | return null;
|
173 | 173 | }
|
174 | 174 | int cachedThumbnailSize = (int) storageIO.getAuxObjectSize(THUMBNAIL_SUFFIX + size);
|
| 175 | + InputStreamIO inputStreamIO = cachedThumbnailSize > 0 ? new InputStreamIO(cachedThumbnailInputStream, cachedThumbnailSize) : null; |
175 | 176 |
|
176 |
| - InputStreamIO inputStreamIO = new InputStreamIO(cachedThumbnailInputStream, cachedThumbnailSize); |
177 |
| - |
178 |
| - inputStreamIO.setMimeType(THUMBNAIL_MIME_TYPE); |
| 177 | + if (inputStreamIO != null) { |
| 178 | + inputStreamIO.setMimeType(THUMBNAIL_MIME_TYPE); |
179 | 179 |
|
180 |
| - String fileName = storageIO.getFileName(); |
181 |
| - if (fileName != null) { |
182 |
| - fileName = fileName.replaceAll("\\.[^\\.]*$", THUMBNAIL_FILE_EXTENSION); |
183 |
| - inputStreamIO.setFileName(fileName); |
| 180 | + String fileName = storageIO.getFileName(); |
| 181 | + if (fileName != null) { |
| 182 | + fileName = fileName.replaceAll("\\.[^\\.]*$", THUMBNAIL_FILE_EXTENSION); |
| 183 | + inputStreamIO.setFileName(fileName); |
| 184 | + } |
| 185 | + } else { |
| 186 | + if (storageIO.getDataFile() != null && cachedThumbnailSize == 0) { |
| 187 | + // We found an older 0 length thumbnail. Newer image uploads will not have this issue. |
| 188 | + // Once cleaned up, this thumbnail will no longer have this issue |
| 189 | + logger.warning("Cleaning up zero sized thumbnail ID: "+ storageIO.getDataFile().getId()); |
| 190 | + storageIO.getDataFile().setPreviewImageFail(true); |
| 191 | + storageIO.getDataFile().setPreviewImageAvailable(false); |
| 192 | + DataFileServiceBean datafileService = CDI.current().select(DataFileServiceBean.class).get(); |
| 193 | + datafileService.save(storageIO.getDataFile()); |
| 194 | + } |
184 | 195 | }
|
185 | 196 | return inputStreamIO;
|
186 | 197 | } catch (Exception ioex) {
|
|
0 commit comments