Java Can';t从azure下载并读取文件名中有空格的文件
我正在尝试下载一个文件,名称如下:Java Can';t从azure下载并读取文件名中有空格的文件,java,azure-files,Java,Azure Files,我正在尝试下载一个文件,名称如下:Some\u name random 15+17.pdf。当我试图读取此文件时,出现以下异常: com.microsoft.azure.storage.StorageException: The specifed resource name contains invalid characters. at com.microsoft.azure.storage.StorageException.translateFromHttpStatus(StorageExce
Some\u name random 15+17.pdf
。当我试图读取此文件时,出现以下异常:
com.microsoft.azure.storage.StorageException: The specifed resource name contains invalid characters.
at com.microsoft.azure.storage.StorageException.translateFromHttpStatus(StorageException.java:175)
at com.microsoft.azure.storage.StorageException.translateException(StorageException.java:94)
at com.microsoft.azure.storage.core.StorageRequest.materializeException(StorageRequest.java:305)
at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:175)
at com.microsoft.azure.storage.file.CloudFile.downloadAttributes(CloudFile.java:1492)
at com.microsoft.azure.storage.file.FileInputStream.<init>(FileInputStream.java:154)
at com.microsoft.azure.storage.file.CloudFile.openRead(CloudFile.java:1819)
at com.microsoft.azure.storage.file.CloudFile.openRead(CloudFile.java:1785)
at ch.prestige.tools.dossier.microservice.service.impl.AzureFileClientProvider.readFileContent(AzureFileClientProvider.java:166)
阅读内容:
private ByteArrayResource readFileContent(CloudFile cloudFile) {
try (final FileInputStream fileInputStream = cloudFile.openRead()) {
final byte[] content = fileInputStream.readAllBytes();
return new ByteArrayResource(content);
} catch (StorageException e) {
log.error("The specified file {} does not exist", cloudFile.getUri(), e);
throw new AzureFileStorageNotAvailableException("The specified file " + cloudFile.getUri() + " does not exist");
} catch (IOException e) {
log.error("Failed to read file content of {}", cloudFile.getUri(), e);
throw new AzureFileStorageNotAvailableException("Failed to read file content of " + cloudFile.getUri());
}
}
当我在azure库中调试时,我注意到正在将名称更改为:
https://Some_name%20random%2015%20+%2017.pdf
是否有可能检索到具有这种名称的文件。对于我上传的其他文件,下载似乎效果不错。请尝试使用最新版本的软件包,例如:
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>8.6.5</version>
</dependency>
com.microsoft.azure
要命名您的文件,该文件也可以用作解决问题的解决方案,请执行以下操作:
这没用,我还是遇到了同样的例外。我的方法处理的文件不遵循此语法,但问题是我无法控制这些文件。我不明白为什么Azure允许你上传这个文件(不是通过java而是使用他们的UI),然后你不允许下载它们。
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>8.6.5</version>
</dependency>