Seven Neu Yun--java get the domain space file list

Source: Internet
Author: User
Tags auth rand

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.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.