Search code examples
swiftinputstreamjclouds

Jclouds swift api upload object directly from inputstream


The following snippet uploads files to object store without any problem

public void uploadObjectFromStream(String container, String name, InputStream stream) {
    SwiftApi swiftApi = getApi();
    createContainerIfAbsent(container, swiftApi);
    ObjectApi objectApi = swiftApi.getObjectApiForRegionAndContainer(REGION, container);
    Payload payload = new InputStreamPayload(stream);
    objectApi.put(name, payload, PutOptions.Builder.metadata(ImmutableMap.of("X-Object-Meta-key1", "value3", "X-Object-Meta-key2", "test"))); // test
}

If I try to upload ~10Mb file I get error

o.j.h.i.HttpWire [SLF4JLogger.java:56] over limit 10485760/262144: wrote temp file
java.lang.OutOfMemoryError: Java heap space

The question is if I can upload object from input stream to object store without saving the stream in application memory or file system.


Solution

  • jclouds does not buffer InputStream unless you enable wire logging. Generally this should be disabled unless you are debugging an issue.