Skip to content

Commit ae61c12

Browse files
author
Gonzalo Gallotti Vazquez
committed
Revert "Tries to determine the content-type of files uploaded to external storage. Previously, if the file extension was .tmp, it was always set to image/jpeg, which caused issues—such as when uploading a PDF: upon downloading it, the file couldn't be opened properly."
This reverts commit 2895a7e.
1 parent 2895a7e commit ae61c12

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

gxcloudstorage-azureblob/src/main/java/com/genexus/db/driver/ExternalProviderAzureStorage.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,17 @@ public String upload(String localFile, String externalFileName, ResourceAccessCo
139139
}
140140

141141
public String upload(String externalFileName, InputStream input, ResourceAccessControlList acl) {
142-
ExternalProviderHelper.InputStreamWithLength streamInfo = null;
143-
try {
144-
streamInfo = ExternalProviderHelper.getInputStreamContentLength(input);
145142

143+
try {
146144
CloudBlockBlob blob = getCloudBlockBlob(externalFileName, acl);
147-
blob.getProperties().setContentType((externalFileName.endsWith(".tmp") && "application/octet-stream".equals(streamInfo.detectedContentType)) ? "image/jpeg" : streamInfo.detectedContentType);
145+
if (externalFileName.endsWith(".tmp")) {
146+
blob.getProperties().setContentType("image/jpeg");
147+
}
148148
try (BlobOutputStream blobOutputStream = blob.openOutputStream()) {
149-
byte[] buffer = new byte[8192];
150-
int bytesRead;
151-
while ((bytesRead = streamInfo.inputStream.read(buffer)) != -1) {
152-
blobOutputStream.write(buffer, 0, bytesRead);
149+
int next = input.read();
150+
while (next != -1) {
151+
blobOutputStream.write(next);
152+
next = input.read();
153153
}
154154
}
155155
return getResourceUrl(externalFileName, acl, DEFAULT_EXPIRATION_MINUTES);
@@ -163,15 +163,6 @@ public String upload(String externalFileName, InputStream input, ResourceAccessC
163163
logger.error("Error uploading file", ex);
164164
return "";
165165
}
166-
finally {
167-
if (streamInfo != null && streamInfo.tempFile != null && streamInfo.tempFile.exists()) {
168-
try {
169-
streamInfo.tempFile.delete();
170-
} catch (Exception e) {
171-
logger.warn("Could not delete temporary file: " + streamInfo.tempFile.getAbsolutePath(), e);
172-
}
173-
}
174-
}
175166
}
176167

177168
public String get(String externalFileName, ResourceAccessControlList acl, int expirationMinutes) {

0 commit comments

Comments
 (0)