|
2 | 2 |
|
3 | 3 | import com.azure.core.exception.ClientAuthenticationException; |
4 | 4 | import com.azure.core.exception.HttpRequestException; |
| 5 | +import com.azure.core.util.Context; |
5 | 6 | import com.azure.identity.DefaultAzureCredential; |
6 | 7 | import com.azure.identity.DefaultAzureCredentialBuilder; |
7 | 8 | import com.azure.storage.blob.BlobClient; |
@@ -189,17 +190,30 @@ public String upload(String localFile, String externalFileName, ResourceAccessCo |
189 | 190 | public String upload(String externalFileName, InputStream input, ResourceAccessControlList acl) { |
190 | 191 | //https://docs.azure.cn/en-us/storage/blobs/storage-blob-upload-java |
191 | 192 | try (ExternalProviderHelper.InputStreamWithLength streamInfo = |
192 | | - ExternalProviderHelper.getInputStreamContentLength(input)) { |
| 193 | + ExternalProviderHelper.getInputStreamContentLength(input)) { |
| 194 | + |
193 | 195 | BlockBlobClient blobClient = |
194 | | - getBlobClient(externalFileName, acl).getBlockBlobClient(); |
195 | | - // Set content type |
| 196 | + getBlobClient(externalFileName, acl).getBlockBlobClient(); |
| 197 | + |
196 | 198 | String contentType = |
197 | | - (externalFileName.endsWith(".tmp") && |
198 | | - "application/octet-stream".equals(streamInfo.detectedContentType)) |
199 | | - ? "image/jpeg" |
200 | | - : streamInfo.detectedContentType; |
| 199 | + (externalFileName.endsWith(".tmp") && |
| 200 | + "application/octet-stream".equals(streamInfo.detectedContentType)) |
| 201 | + ? "image/jpeg" |
| 202 | + : streamInfo.detectedContentType; |
| 203 | + |
201 | 204 | BlobHttpHeaders headers = new BlobHttpHeaders().setContentType(contentType); |
202 | | - blobClient.upload(streamInfo.inputStream, streamInfo.contentLength, true); |
| 205 | + blobClient.uploadWithResponse( |
| 206 | + streamInfo.inputStream, |
| 207 | + streamInfo.contentLength, |
| 208 | + headers, |
| 209 | + null, |
| 210 | + null, |
| 211 | + null, |
| 212 | + null, |
| 213 | + null, |
| 214 | + Context.NONE |
| 215 | + ); |
| 216 | + |
203 | 217 | return getResourceUrl(externalFileName, acl, DEFAULT_EXPIRATION_MINUTES); |
204 | 218 | } |
205 | 219 | catch (Exception ex) { |
@@ -281,9 +295,7 @@ public String copy(String objectName, String newName, ResourceAccessControlList |
281 | 295 | try { |
282 | 296 | BlobClient sourceBlob = getBlobClient(objectName, acl); |
283 | 297 | BlobClient targetBlob = getBlobClient(newName, acl); |
284 | | - |
285 | 298 | String sourceBlobUrl; |
286 | | - |
287 | 299 | if (useManagedIdentity) { |
288 | 300 | //Needs RBAC permissions: https://learn.microsoft.com/en-us/azure/storage/blobs/authorize-access-azure-active-directory |
289 | 301 | sourceBlobUrl = sourceBlob.getBlobUrl(); |
@@ -334,7 +346,6 @@ public String copy(String objectUrl, String newName, String tableName, String fi |
334 | 346 |
|
335 | 347 | sourceBlobUrl = sourceBlob.getBlobUrl() + "?" + sourceBlob.generateSas(values); |
336 | 348 | } |
337 | | - |
338 | 349 | targetBlob.beginCopy(sourceBlobUrl, null); |
339 | 350 | return getResourceUrl(newName, acl, defaultExpirationMinutes); |
340 | 351 |
|
@@ -398,7 +409,6 @@ public boolean existsDirectory(String directoryName) { |
398 | 409 | try { |
399 | 410 | // List all blobs with the directory prefix |
400 | 411 | ListBlobsOptions options = new ListBlobsOptions().setPrefix(directoryName); |
401 | | - |
402 | 412 | // Check if there are any blobs with this prefix |
403 | 413 | boolean exists = false; |
404 | 414 | for (BlobItem blobItem : publicContainerClient.listBlobs(options, null)) { |
@@ -483,7 +493,6 @@ public void renameDirectory(String directoryName, String newDirectoryName) { |
483 | 493 | } |
484 | 494 | } |
485 | 495 | } |
486 | | - |
487 | 496 | // Delete the original directory |
488 | 497 | deleteDirectory(directoryName); |
489 | 498 | } catch (Exception ex) { |
|
0 commit comments