Downloading Files Through SDK

The Java sample code is as follows:

import java.io.IOException;

import com.xiaomi.infra.galaxy.fds.client.FDSClientConfiguration;
import com.xiaomi.infra.galaxy.fds.client.GalaxyFDS;
import com.xiaomi.infra.galaxy.fds.client.GalaxyFDSClient;
import com.xiaomi.infra.galaxy.fds.client.credential.BasicFDSCredential;
import com.xiaomi.infra.galaxy.fds.client.credential.GalaxyFDSCredential;
import com.xiaomi.infra.galaxy.fds.client.exception.GalaxyFDSClientException;
import com.xiaomi.infra.galaxy.fds.client.model.FDSObject;
import com.xiaomi.infra.galaxy.fds.client.model.FDSObjectInputStream;

public class FDSDemo {

  private static final String APP_ACCESS_KEY = ""; // Cloud Service Key AppKey
  private static final String APP_ACCESS_SECRET = ""; // Cloud Service Key AppSecret

  private static final String BUCKET_NAME = "fds-demo"; // Created Bucket Name 
  private static final String OBJECT_NAME = "10MB.bin"; // Uploaded Object Name

  public static void main(String[] args)
      throws GalaxyFDSClientException, IOException {
    GalaxyFDSCredential credential = new BasicFDSCredential(
        APP_ACCESS_KEY, APP_ACCESS_SECRET);

    // Structure Client
    String endpoint = "awsbj0.fds.api.xiaomi.com"; // Confirm that it is in the same region as Bucket
    FDSClientConfiguration fdsConfig = new FDSClientConfiguration(endpoint);
    fdsConfig.enableHttps(true);
    fdsConfig.enableCdnForDownload(false);
    GalaxyFDS fdsClient = new GalaxyFDSClient(credential, fdsConfig);

    // 1k content into the buffer before downloaded the file
    FDSObject object = fdsClient.getObject(BUCKET_NAME, OBJECT_NAME);
    FDSObjectInputStream in = object.getObjectContent();
    byte[] buffer = new byte[1024];
    int totalReadLen = 0;
    int readLen = 0;
    while ((readLen = in.read(buffer, totalReadLen,
        buffer.length - totalReadLen)) > 0) {
      totalReadLen += readLen;
    }
    in.close();
  }
}

Add Pom dependency:

<dependencies>
  <dependency>
    <groupId>com.xiaomi.infra.galaxy</groupId>
    <artifactId>galaxy-fds-sdk-java</artifactId>
    <version>3.0.13</version>
  </dependency>
</dependencies>

results matching ""

    No results matching ""