我正在使用jclouds API将文件上传到azure blob,但我找不到使用jClouds API生成SAS的任何方法,因此使用Azure API为特定blob创建SAS。 我面临的问题是我尝试上传的文件在其名称中包含本地化字符,例如“Jérôme”我必须在上传时在特定级别编码和解码,我确保在SAS生成时我传递解码(实际)文件名但我无法使用生成的SAS访问相同的文件。
PS。我在上传和SAS生成中尝试过编码和解码字符串(文件名)的不同组合,但都是徒劳的。
我得到的错误是“没有这样的blob存在”,在某些情况下“签名验证失败”
任何人都可以用适当的方法指导我吗?
如果需要代码段,请告诉我。
上传
try (BlobStoreContext context = ContextBuilder.newBuilder("azureblob")
.credentials(this.storeName, this.storeKey)
.buildView(BlobStoreContext.class)) {
final BlobStore store = context.getBlobStore();
payload.getContentMetadata().setContentLength(blobSize);
final Blob blob = store.blobBuilder(URLEncoder.encode(blobName, StorageConstants.UNICODE_FORMAT)).payload(payload).build();
logger.debug("Uploading...");
store.putBlob(this.containerName, blob);
logger.debug("Uploaded...");
return true;
} catch (IOException e) {
logger.error("IOException while uploading file to azure blob", e);
return false;
} catch (Exception e) {
logger.error("Exception while uploading file to azure blob", e);
return false;
}
SAS Generation
String url = "";
try
{
final CloudBlobContainer container = getUploadContainer();
final CloudBlockBlob blob = container.getBlockBlobReference(blobName);
url = blob.getUri() +"?"+ blob.generateSharedAccessSignature(getPolicy(), null);
} catch (StorageException e) {
logger.error("Storage Exception was encounter in generateAttachmentSasUrl() :", e);
} catch (InvalidKeyException e) {
logger.error("Invalid Key Exception was encountered in generateAttachmentSasUrl() :", e);
} catch (URISyntaxException e) {
logger.error("Problems creating an URI was encounter in generateAttachmentSasUrl() : ", e);
}