Java 使用元数据上载到Swift容器
我使用Java和jclouds SDK将文件作为多部分上传到Swift容器中,上传过程很顺利,但我需要向文件中添加元数据,我注意到有一个名为Java 使用元数据上载到Swift容器,java,openstack-swift,jclouds,Java,Openstack Swift,Jclouds,我使用Java和jclouds SDK将文件作为多部分上传到Swift容器中,上传过程很顺利,但我需要向文件中添加元数据,我注意到有一个名为getContentMetadata()的函数,它可以获取元数据,如内容长度和类型,但我无法添加自定义元数据,尝试将put选项强制转换为元数据,没有生成错误,但在运行代码时生成了异常,代码在这里 try { PutOptions putOptions = PutOptions.Builder.metadata(ImmutableMap.of(
getContentMetadata()
的函数,它可以获取元数据,如内容长度和类型,但我无法添加自定义元数据,尝试将put选项强制转换为元数据,没有生成错误,但在运行代码时生成了异常,代码在这里
try {
PutOptions putOptions = PutOptions.Builder.metadata(ImmutableMap.of("test", String.valueOf(strValue)));
ByteSource fileBytes = Files.asByteSource(file);
Payload payload = Payloads.newByteSourcePayload(fileBytes);
///setting the header for the request
payload.getContentMetadata().setContentLength(file.length());
payload.getContentMetadata().setContentType(contentType);
payload.setContentMetadata((MutableContentMetadata) putOptions);
Blob blob = blobStore.blobBuilder(file.getName()).payload(payload).build();
///sednig the request
blobStore.putBlob("testContainer", blob, multipart());
return contentLength;
}
行payload.setContentMetadata((MutableContentMetadata)putOptions)代码>生成了一个异常
你知道怎么解决这个问题吗?
谢谢您应该通过BlobBuilder
设置元数据,例如
Blob blob = blobStore.blobBuilder(file.getName())
.payload(fileBytes)
.contentLength(file.length()
.contentType(contentType)
.userMetadata(ImmutableMap.of("test", String.valueOf(strValue)))
.build();
您应该通过BlobBuilder设置元数据,例如
Blob blob = blobStore.blobBuilder(file.getName())
.payload(fileBytes)
.contentLength(file.length()
.contentType(contentType)
.userMetadata(ImmutableMap.of("test", String.valueOf(strValue)))
.build();