How to get stored images/videos from Object Storage in IBM Bluemix


What is Object Storage?

IBM® Object Storage for Bluemix® provides you with access to a fully provisioned Swift Object Storage account to manage your data. Swift provides a fully distributed, API-accessible storage platform. You can use it directly in your applications or for backups, making it ideal for cost effective, scale-out storage.

This blog will help you to get images/videos from Cloud Data Storage(Object Storage) into your application.


Below shown is the UI of Object Storage. I have 4 images & 1 video uploaded to a container named store1.


Front end of the application:


Code to get the image/video from Object Storage

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

String imgoption = request.getParameter(“imgOpt”); //Takes the user input

String envApp = System.getenv(“VCAP_APPLICATION”);

String envServices = System.getenv(“VCAP_SERVICES”);


JSONParser parser = new JSONParser();


Object obj = parser.parse(envServices);

JSONObject jsonObject = (JSONObject) obj;

JSONArray vcapArray = (JSONArray) jsonObject.get(“Object-Storage”);

JSONObject vcap = (JSONObject) vcapArray.get(0);

JSONObject credentials = (JSONObject) vcap.get(“credentials”);

String userId = credentials.get(“userId”).toString();

String password = credentials.get(“password”).toString();

String auth_url = credentials.get(“auth_url”).toString() + “/v3”;

String domain = credentials.get(“domainName”).toString();

String project = credentials.get(“project”).toString();

Identifier domainIdent = Identifier.byName(domain);

Identifier projectIdent = Identifier.byName(project);

OSClientos = OSFactory.builderV3()


.credentials(userId, password)

.scopeToProject(projectIdent, domainIdent)



SwiftAccount account = os.objectStorage().account().get();

ObjectStorageService objectStorage = os.objectStorage();

List<? extends SwiftContainer> containers = os.objectStorage().containers().list();

System.out.println(containers); // Prints the list of containers

List<? extends SwiftObject> objs = os.objectStorage().objects().list(“store1”);

System.out.println(obj); //Prints the list of objects inside the container store1

SwiftObject fileObj = objectStorage.objects().get(“store1”,imgoption);


String mimeType = fileObj.getMimeType();

DLPayload payload =;

InputStream in = payload.getInputStream();


OutputStream out = response.getOutputStream();

IOUtils.copy(in, out);



}catch(Exception e){




Ensure that you have added the dependency to POM.XML file






































Please note that OpenStack4j has some of the same libraries that are also provided in the Liberty profile if you are running this Java application on Bluemix. To avoid this you should use reverse class loading or exclude jaxrs from the enabled features. 

This is a Java app which was deployed on a Node.JS runtime.

Output of the app:

Video & Image


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s