使用元数据上传到Swift容器

时间:2018-03-31 10:50:49

标签: java openstack-swift jclouds

我使用Java和jclouds SDK将文件作为multipart上传到Swift容器,上传很顺利但我需要向文件添加元数据,我注意到有一个名为getContentMetadata()的函数可以获取元数据,如内容长度和类型,但我无法添加自定义元数据,尝试将放置选项转换为元数据,没有生成错误但是当我运行代码时生成异常,代码在这里< / p>

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);生成了异常

任何想法如何解决这个问题? 感谢

1 个答案:

答案 0 :(得分:1)

您应该通过ptr设置元数据,例如,

    int pSize = this->getNumElem();
    T tempArray[pSize] = {0};