Upload files to Oracle Storage Cloud Service, Java basic example


Obtain connection information in your OPC subscription page:
StorageCloudBlogEntry
Download Oracle Storage Cloud SDK:
Create a java Class with the following code:

package storageupload;

import oracle.cloud.storage.*;

import oracle.cloud.storage.model.*;

import oracle.cloud.storage.exception.*;

import java.io.*;

import java.util.*;

import java.net.*;

public class UploadingSegmentedObjects {

   public static void main(String[] args) {

       try {

           CloudStorageConfig myConfig = new CloudStorageConfig();

           myConfig.setServiceName(“Storage-usoracleXXXXX”)

               .setUsername(“xxxxxxxxx@yyyyyyyyy.com”)

               .setPassword(“xxxxxxxxxxxxxxxxx”.toCharArray())

               .setServiceUrl(“https://storage.us2.oraclecloud.com”);

           CloudStorage myConnection = CloudStorageFactory.getStorage(myConfig);

           System.out.println(“\nConnected!!\n”);

           if ( myConnection.listContainers().isEmpty() ){

               myConnection.createContainer(“myContainer”);

           }

           FileInputStream fis = new FileInputStream(“C:\\temp\\hello.txt”);

           myConnection.storeObject(“myContainer”, “C:\\temp\\hello.txt”, “text/plain”, fis);

           fis = new FileInputStream(“C:\\temp\\hello.txt”);

           myConnection.storeObject(“myContainer”, “C:\\temp\\hello1.txt”, “text/plain”, fis);

           fis = new FileInputStream(“C:\\temp\\hello.txt”);

           myConnection.storeObject(“myContainer”, “C:\\temp\\hello2.txt”, “text/plain”, fis);

           List myList = myConnection.listObjects(“myContainer”, null);

           Iterator it = myList.iterator();

           while (it.hasNext()) {

               System.out.println((it.next().getKey().toString()));

           }

       } catch (Exception e) {

          e.printStackTrace();

       }      

   }

}

Test  it and enjoy! 😉

More info

Technical: http://docs.oracle.com/cloud/latest/storagecs_common/index.html

Commercial: https://cloud.oracle.com/storage

Leave a Reply

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

WordPress.com Logo

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.