All Products
Search
Document Center

Object Storage Service:Use Object FC Access Points

Last Updated:Dec 21, 2023

After you create an Object FC Access Point, OSS automatically generates an alias for the Object FC Access Point. You can use the alias to call the GetObject operation.

Prerequisites

A function that is used to process GetObject requests is compiled. For more information, see Compile a function that is used to process GetObject requests.

Use OSS SDKs

Java

OSS SDK for Java 3.17.2 and later allow you to access OSS resources by using the alias of an Object FC Access Point.

import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.GetObjectRequest;
import java.io.File;

public class Demo {

    public static void main(String[] args) throws Exception {
        // Use the public endpoint of the Object FC Access Point to access OSS resources. 
        String endpoint = "https://oss-cn-qingdao.aliyuncs.com";
        // Use the internal endpoint of the Object FC Access Point to access OSS resources. 
        // String endpoint = "https://oss-cn-qingdao-internal.aliyuncs.com";
        // Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // Specify the alias of the Object FC Access Point. 
        String bucketName = "fc-ap-01-3b00521f653d2b3223680ec39dbbe2****-opapalias";
        // Specify the full path of the object. Do not include the bucket name in the full path. 
        String objectName = "yourObjectName";
        // Specify the full path of the downloaded object on your computer. 
        String pathName = "yourPathName";

        // Create an OSSClient instance. 
        OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider);

        try {
            // Download the object to the specified path on your computer. If a file that has the same name already exists, the downloaded object overwrites the file. Otherwise, the downloaded object is saved in the path. 
            // If you do not specify a local path for the downloaded object, the downloaded object is saved to the path of the project to which the sample program belongs. 
            ossClient.getObject(new GetObjectRequest(bucketName, objectName), new File(pathName));
        } catch (OSSException oe) {
            System.out.println("Caught an OSSException, which means your request made it to OSS, "
                    + "but was rejected with an error response for some reason.");
            System.out.println("Error Message:" + oe.getErrorMessage());
            System.out.println("Error Code:" + oe.getErrorCode());
            System.out.println("Request ID:" + oe.getRequestId());
            System.out.println("Host ID:" + oe.getHostId());
        } catch (ClientException ce) {
            System.out.println("Caught an ClientException, which means the client encountered "
                    + "a serious internal problem while trying to communicate with OSS, "
                    + "such as not being able to access the network.");
            System.out.println("Error Message:" + ce.getMessage());
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
    }
} 

Python

OSS SDK for Python 2.18.3 and later allow you to access OSS resources by using the alias of an Object FC Access Point.

# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider

auth = oss2.ProviderAuth(EnvironmentVariableCredentialsProvider())
# Use the public endpoint of the Object FC Access Point to access OSS resources. 
endpoint = "https://oss-cn-qingdao.aliyuncs.com"
# Use the internal endpoint of the Object FC Access Point to access OSS resources.  
# endpoint = "https://oss-cn-qingdao-internal.aliyuncs.com"
# Specify the alias of the Object FC Access Point. 
bucket_name = "fc-ap-01-3b00521f653d2b3223680ec39dbbe2****-opapalias"
bucket = oss2.Bucket(auth, endpoint=endpoint, bucket_name=bucket_name)

# Specify the full path of the object. Do not include the bucket name in the full path. 
# Specify the full path of the downloaded object on your computer. If a file that has the same name already exists, the downloaded object overwrites the file. Otherwise, the downloaded object is saved in the path. 
bucket.get_object_to_file('yourObjectName', 'yourLocalFile')

Use ossutil

When you use ossutil to request OSS resources, you must set the bucket name to the alias of an Object FC Access Point. Example:

ossutil cp oss://fc-ap-01-3b00521f653d2b3223680ec39dbbe2****-opapalias/demo.txt /Users/demo/Desktop/demo.txt

For more information about common commands, see Common commands.

Use RESTful APIs

When you call the GetObject operation to request OSS resources, you must add the alias of an Object FC Access Point to the Host header. Example:

GET /ObjectName HTTP/1.1
Host: fc-ap-01-3b00521f653d2b3223680ec39dbbe2****-opapalias.oss-cn-qingdao.aliyuncs.com
Date: GMT Date
Authorization: SignatureValue