Apache Jclouds使用SAS令牌将报告上传到Azure

时间:2019-12-17 12:26:51

标签: azure azure-storage azure-storage-blobs jclouds sas-token

Jcloud版本-2.2.0

使用Azure密钥和秘密密钥-运行正常。 (能够上传文件,它将创建test1文件夹mycontainer并上传test-data.log文件)

it  should "Upload a file" in {


    val azureKey = AppConf.getStorageKey("azure")
    val azureToken = AppConf.getStorageSecret("azure")

    import org.jclouds.ContextBuilder
    import org.jclouds.blobstore.BlobStoreContext
    val context = ContextBuilder.newBuilder("azureblob").credentials(azureKey, azureToken).buildView(classOf[BlobStoreContext])

    var blobStore = context.getBlobStore()
    blobStore.createContainerInLocation(null, "mycontainer")
    val fileObj = new File("src/test/resources/test-data.log")
    val payload = Files.asByteSource(fileObj)
    val blob = blobStore.blobBuilder("test1/test-data.log").payload(payload).contentLength(payload.size()).build()
    blobStore.putBlob("mycontainer", blob, new PutOptions().multipart())
    context.close()

}

使用AZURE SAS令牌-不起作用-无法上传文件

it  should "Upload a file" in {

    val sasToken = AppConf.getSSAToken("azure")
    val azureKey = AppConf.getStorageKey("azure")


    import org.jclouds.ContextBuilder
    import org.jclouds.blobstore.BlobStoreContext
    val context = ContextBuilder.newBuilder("azureblob").credentials(azureKey, sasToken).buildView(classOf[BlobStoreContext])

    var blobStore = context.getBlobStore()
    blobStore.createContainerInLocation(null, "mycontainer")
    val fileObj = new File("src/test/resources/test-data.log")
    val payload = Files.asByteSource(fileObj)
    val blob = blobStore.blobBuilder("test1/test-data.log").payload(payload).contentLength(payload.size()).build()
    blobStore.putBlob("mycontainer", blob, new PutOptions().multipart())
    context.close()

}

使用SAS令牌时出错

org.jclouds.azure.storage.AzureStorageResponseException: command [method=org.jclouds.azureblob.AzureBlobClient.public abstract void org.jclouds.azureblob.AzureBlobClient.putBlock(java.lang.String,java.lang.String,java.lang.String,org.jclouds.io.Payload)[mycontainer, test1/test-data.log, AAAAAQ==, [content=true, contentMetadata=[cacheControl=null, contentDisposition=null, contentEncoding=null, contentLanguage=null, contentLength=7986, contentMD5=null, contentType=application/unknown, expires=null], written=false, isSensitive=false]], request=PUT https://test.blob.core.windows.net/mycontainer/test1/test-data.log?comp=block&blockid=AAAAAQ%3D%3D HTTP/1.1] failed with code 400, error: AzureError{requestId='c13bc6b2-f01e-0020-5acd-b4114e000000', code='InvalidQueryParameterValue', message='Value for one of the query parameters specified in the request URI is invalid.
RequestId:c13bc6b2-f01e-0020-5acd-b4114e000000
Time:2019-12-17T11:31:17.8460459Z', context='{QueryParameterValue=block, QueryParameterName=comp, Reason=}'}
com.google.common.util.concurrent.UncheckedExecutionException: org.jclouds.azure.storage.AzureStorageResponseException: command [method=org.jclouds.azureblob.AzureBlobClient.public abstract void org.jclouds.azureblob.AzureBlobClient.putBlock(java.lang.String,java.lang.String,java.lang.String,org.jclouds.io.Payload)[mycontainer, test1/test-data.log, AAAAAQ==, [content=true, contentMetadata=[cacheControl=null, contentDisposition=null, contentEncoding=null, contentLanguage=null, contentLength=7986, contentMD5=null, contentType=application/unknown, expires=null], written=false, isSensitive=false]], request=PUT https://test.blob.core.windows.net/mycontainer/test1/test-data.log?comp=block&blockid=AAAAAQ%3D%3D HTTP/1.1] failed with code 400, error: AzureError{requestId='c13bc6b2-f01e-0020-5acd-b4114e000000', code='InvalidQueryParameterValue', message='Value for one of the query parameters specified in the request URI is invalid.
RequestId:c13bc6b2-f01e-0020-5acd-b4114e000000
Time:2019-12-17T11:31:17.8460459Z', context='{QueryParameterValue=block, QueryParameterName=comp, Reason=}'}

我的观察

我认为使用SAS令牌时,如果我们使用blobStore.blobBuilder("test1/test-data.log")这样的路径,例如format(test1 / test-data.log),那么它就坏了。

blobBuilder似乎无法创建文件夹

但是

当我仅使用blobStore.blobBuilder("test-data.log")而不提及文件夹时,test-data.log就可以了。 (可以仅上传test-data.log文件,而无需创建任何文件夹。)

有人遇到这个问题吗?

吉拉票:https://issues.apache.org/jira/browse/JCLOUDS-1428?focusedCommentId=16998110&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-16998110

0 个答案:

没有答案