Image handling and file upload bug fixes.
parent
204c2ee39d
commit
0f44e9d70c
|
|
@ -81,9 +81,10 @@ public class BinaryAssetBlobDataProvider implements BinaryAssetDataProvider {
|
||||||
final Blob blob = resultSet.getBlob("asset_data");
|
final Blob blob = resultSet.getBlob("asset_data");
|
||||||
try ( InputStream inputStream = blob.getBinaryStream()) {
|
try ( InputStream inputStream = blob.getBinaryStream()) {
|
||||||
byte[] buffer = new byte[8192];
|
byte[] buffer = new byte[8192];
|
||||||
int length;
|
int length = inputStream.read(buffer);
|
||||||
while ((length = inputStream.read(buffer)) != -1) {
|
while (length != -1) {
|
||||||
outputStream.write(buffer, 0, length);
|
outputStream.write(buffer, 0, length);
|
||||||
|
length = inputStream.read(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -109,13 +110,24 @@ public class BinaryAssetBlobDataProvider implements BinaryAssetDataProvider {
|
||||||
final Path tmpFilePath = Files.createTempFile("upload", fileName);
|
final Path tmpFilePath = Files.createTempFile("upload", fileName);
|
||||||
int fileSize = 0;
|
int fileSize = 0;
|
||||||
try ( OutputStream outputStream = Files.newOutputStream(tmpFilePath)) {
|
try ( OutputStream outputStream = Files.newOutputStream(tmpFilePath)) {
|
||||||
int length;
|
|
||||||
byte[] buffer = new byte[8192];
|
byte[] buffer = new byte[8192];
|
||||||
while ((length = inputStream.read(buffer)) != -1) {
|
int length = inputStream.read(buffer);
|
||||||
outputStream.write(buffer);
|
fileSize += length;
|
||||||
|
while(length != -1) {
|
||||||
|
outputStream.write(buffer, 0, length);
|
||||||
|
length = inputStream.read(buffer);
|
||||||
fileSize += length;
|
fileSize += length;
|
||||||
}
|
}
|
||||||
outputStream.flush();
|
// while ((length = inputStream.read(buffer)) != -1) {
|
||||||
|
// outputStream.write(buffer);
|
||||||
|
// fileSize += length;
|
||||||
|
// }
|
||||||
|
// int dataByte = inputStream.read();
|
||||||
|
// while (dataByte != -1) {
|
||||||
|
// fileSize++;
|
||||||
|
// outputStream.write(dataByte);
|
||||||
|
// dataByte = inputStream.read();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
final Blob data = BlobProxy.generateProxy(
|
final Blob data = BlobProxy.generateProxy(
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,9 @@ import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import javax.enterprise.context.Dependent;
|
import javax.enterprise.context.Dependent;
|
||||||
|
|
@ -126,12 +129,18 @@ public class ImageService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return outputStream.toByteArray();
|
final byte[] result = outputStream.toByteArray();
|
||||||
|
// try {
|
||||||
|
// Files.delete(tmpFilePath);
|
||||||
|
// } catch (IOException ex) {
|
||||||
|
// LOGGER.warn("Failed to delete temporary file.", ex);
|
||||||
|
// }
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private java.awt.Image scaleImage(
|
private java.awt.Image scaleImage(
|
||||||
final BufferedImage image,
|
final BufferedImage image,
|
||||||
final float scaleToWidth,
|
final float scaleToWidth,
|
||||||
final float scaleToHeight
|
final float scaleToHeight
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@
|
||||||
</c:if>
|
</c:if>
|
||||||
<c:choose>
|
<c:choose>
|
||||||
<c:when test="#{CmsImageEditStepModel.dataAvailable}">
|
<c:when test="#{CmsImageEditStepModel.dataAvailable}">
|
||||||
<figure>
|
<figure class="mt-3">
|
||||||
<img alt="#{CmsAssetsStepsDefaultMessagesBundle['image.editstep.preview.alt']}"
|
<img alt="#{CmsAssetsStepsDefaultMessagesBundle['image.editstep.preview.alt']}"
|
||||||
src="#{mvc.basePath}/#{ContentSectionModel.sectionName}/assets/#{CmsSelectedAssetModel.assetPath}/@image-edit-download?width=320"
|
src="#{mvc.basePath}/#{ContentSectionModel.sectionName}/assets/#{CmsSelectedAssetModel.assetPath}/@image-edit-download?width=320"
|
||||||
width="320" />
|
width="320" />
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue