About Shares

About Shares

Contents

Introduction

The Java SDK allows you to retrieve, create, and delete shares. The following examples include code samples to help you get started with shares.

Examples

createImagesShare

public Share createImagesShare(OAuthToken token, String shareName, List<FileMetadata> imageFiles) throws IOException, CloudHttpException
{
    CloudApp app = new CloudApp("appname", "key", "secret", "redirectURI");
    CloudClientContext context = new CloudClientContext(app, token);
    CloudClient client = new CloudClient(context);

    // create a list of resource from the supplied list of image files.
    List<ShareResource> resources = new ArrayList<>();
    for (FileMetadata imageFile : imageFiles)
    {
        String name = imageFile.getName();
        String location = imageFile.getUri();
        long size = imageFile.getSize();
        ShareResource resource = new ShareResource(name, "file", "image", location, size);

        resources.add(resource);
    }

    return client.postShare(shareName, resources, null);
}

deleteShare

public void deleteShare(OAuthToken token, Share share) throws IOException, CloudHttpException
{
    CloudApp app = new CloudApp("appname", "key", "secret", "redirectURI");
    CloudClientContext context = new CloudClientContext(app, token);
    CloudClient client = new CloudClient(context);

    client.deleteShare(share.getUid());
}

getShares

public List<Share> getShares(OAuthToken token) throws IOException, CloudHttpException
{
    CloudApp app = new CloudApp("appname", "key", "secret", "redirectURI");
    CloudClientContext context = new CloudClientContext(app, token);
    CloudClient client = new CloudClient(context);

    // Shares are retrieved one page at a time.  For purposes of this sample, all shares will be retrieved.
    String cursor = null;
    List<Share> rv = new ArrayList<>();
    do {
        // retrieve one page of shares.
        Shares shares = client.getShares(cursor, (Date)null, null, null);
        rv.addAll(shares.getShares());

        // save cursor value for retrieving the next page.
        cursor = shares.getNextCursor();
    } while (cursor != null);

    return rv;
}

Copyright © 2015-2017, Verizon and/or its Licensors. All rights reserved.