Skip to content

Uploading your first file

Tomas Celaya edited this page Dec 29, 2017 · 1 revision

In this short guide we'll explore a simple upload to manta. If you still need to configure your client, please see the relevant getting started guide.

Simple strings

Let's create a MantaClient using the ConfigContext created in the previous guide and start with storing some simple strings.

ConfigContext config = new ChainedConfigContext(
  new DefaultsConfigContext(),
  new EnvVarConfigContext(),
  new SystemSettingsConfigContext());

MantaClient client = new MantaClient(config);

String strPath = "/you/stor/strings"
String strContent = "Strings... in... manta!"

MantaObjectResponse strPutResponse = client.put(strPath, strContent);

We should now have a response object indicating that the string was uploaded successfully. Take some time to inspect the methods of the MantaObjectResponse class to see what kinds of data it contains, or print the response directly (newlines have been added for readability):

System.out.println(strPutResponse);

/*
  com.joyent.manta.client.MantaObjectResponse{
    path='/you/stor/strings',
    contentLength=null,
    contentType='text/plain; charset=UTF-8',

    etag='a5b3c934-3244-45ed-e8c7-b11b994824e7',

    mtime='Fri, 29 Dec 2017 20:14:33 GMT',
    type='null',

    requestId='df1ef809-ecd4-11e7-aec7-e14a337fbd5e',

    httpHeaders=MantaHttpHeaders{
      wrappedHeaders={

        connection=keep-alive,

        x-response-time=5899,
        x-server-name=56564894-a7c2-470e-a218-3d859e7e1687,
        computed-md5=FsdpTF2dV/QZ50ylTCIA1w==,
        content-type=text/plain; charset=UTF-8,
        x-request-id=df1ef809-ecd4-11e7-aec7-e14a337fbd5e,
        x-load-balancer=165.225.172.14,
        server=Manta,
        date=Fri, 29 Dec 2017 20:14:33 GMT,
        last-modified=Fri, 29 Dec 2017 20:14:33 GMT,
        etag=a5b3c934-3244-45ed-e8c7-b11b994824e7
      }
    },

    directory=false
  }
*/

This may be a lot to take in at first glance but empty lines have been added around the most significant properties:

  • directory indicating we've create a file instead of a directory. Manta uses directories to organize files and optimize finding nearby files.
  • requestId is a unique identifier for each request. Debugging issues with java-manta and manta relies on tracing requests using this ID.
  • etag is a unique identifier for the actual object content. etags will become meaningful in a future guide on links.
  • httpHeaders is an instance of MantaHttpHeaders which contains HTTP headers from the response and provides getters for commonly-access header values. Notice the connection=keep-alive header indicating that the connection will be reused.

What about Files, InputStreams, OutputStreams, etc?

Hop over to The many flavors of PUT guide for a comprehensive description of the variety of ways to upload object content.