First, register seven cattle cloud, get key, personal center--> Key Management
Of course, we can build storage space in object storage, upload pictures and download pictures in content management Jia. Each picture on seven cows has its own single link, but as the business expands, it needs access to all the pictures below a domain, the exact name of the picture is not certain, or there will be changes later. So you need to implement a list of access space files.
Read the seven Neu Yun Java SDK Documentation implementation process as follows:
//constructs a configuration class with the specified Zone object Configuration cfg = new Configuration (ZONE.ZONE0 ());
Other parameter reference class annotation String AccessKey = "Your access key";
String Secretkey = "Your secret key";
String bucket = "your bucket name";
Auth Auth = auth.create (AccessKey, Secretkey);
Bucketmanager Bucketmanager = new Bucketmanager (auth, CFG);
filename prefix String prefix = "";
Length limit for each iteration, maximum 1000, recommended value 1000 int limit = 1000; Specifies the directory separator, listing all public prefixes (impersonation listing effect).
The default value is an empty string, string delimiter = ""; Enumerates the space file lists Bucketmanager.filelistiterator Filelistiterator = bucketmanager.createfilelistiterator (bucket, prefix,
Limit, delimiter);
while (Filelistiterator.hasnext ()) {//Process fetched file list result fileinfo[] items = Filelistiterator.next ();
for (FileInfo item:items) {System.out.println (Item.key);
System.out.println (Item.hash);
System.out.println (item.fsize);
System.out.println (Item.mimetype);
System.out.println (Item.puttime);
System.out.println (Item.enduser); }
}
Explain the above code, AccessKey is Accesskey,secretkey is your secretkey,bucket is a storage space of the external chain default domain name.
Prefix to find the name of a file prefix in this domain, which is equivalent to querying all pictures that match the criteria by prefix.
After we get to the file list, the network transmits the form of the file stream, so it needs to be used locally to transform the convection in the code.
Convert FileInfo into BufferedImage
Enumerates the space file lists
bucketmanager.filelistiterator filelistiterator = Bucketmanager.createfilelistiterator (BUCKET, prefix, limit, delimiter);
fileinfo[] Fileinfos = Filelistiterator.next ();
Random rand = new Random ();
int index = Rand.nextint (fileinfos.length);
FileInfo FileInfo = Fileinfos[index];
System.out.println ("output:>>>" + fileinfo.key);
Bytearrayinputstream in = new Bytearrayinputstream (Getimagefromnetbyurl (bucket_host_name + "/" + FileInfo.key));
@NonNull bufferedimage oriimage = Imageio.read (in);
return oriimage;
Note that the bucket_host_name need to be stitching up the network protocol, and that the seven Neu Yun defaults to HTTP.