Alibaba Cloud Object Storage OSS Introduction and Usage
- quick to use
- development access
- Advanced Features
- common problem
what is OSS
Alibaba Cloud [Object Storage] OSS (Object Storage Service) is a massive, secure, low-cost, and highly reliable cloud storage service that provides 99.9999999999% (12 9s) data durability and 99.995% data availability. A variety of storage types are available to fully optimize storage costs. It is very suitable for storing unstructured data, such as videos, graphics, logs, text files, and various App applications, multi-terminal synchronization software, files from network disk download stations, etc. The size of a single file ranges from 1 byte to 48.8TB , which can be stored The number is unlimited .
For non-special scenarios , you can directly select the standard type .
All billing services of OSS are billed separately. For example, if you store files, you will incur storage fees; if you access files stored in OSS through the external network, you will incur fees for outgoing traffic from the external network; using the image processing service to process images from OSS will generate images. processing fees, etc.
The common cost details are listed as follows (without considering the situation with [CDN] ):
Storage charges : Standard storage (locally redundant) capacity
Pay -as-you-go : 0.12 yuan/GB/month
Annual and monthly subscription : Standard (local redundant LRS) storage package 100G annual price of 99 yuan = 0.99 yuan / GB / year = = 0.08 yuan / GB / month
The part of the annual content within 100G will be deducted through the storage package, and the excess part will be automatically billed according to the amount
Traffic cost : outgoing traffic from the external network
Pay-as-you-go : 00:00-08:00 (idle time): 0.25 yuan /GB, 8:00-24:00 (busy time): 0.50 yuan/GB
Yearly subscription and monthly subscription : 100G downlink traffic package annual price 441 = 0.36 yuan / GB
Within a year, there is a 100G download traffic deduction from the external network, which will be updated on the 1st of each month, and the excess will be automatically billed according to the amount
Request fees : Put type requests, Get type requests
- Billing by volume : 0.01 yuan /10,000 times
- Monthly subscription : not supported
Image processing fee :
Image processing : 0-10TB per month: free, larger than 10TB: 0.025 yuan/G
- Advanced image compression : low specification (below 800×600): 0.025 yuan/thousand times, medium size (below 1600×1200): 0.1 yuan/thousand times
The sum of all the above costs is the total cost. It can be seen that the main traffic cost is expensive , and the others are very cheap and can be ignored. Fee details address : Please refer to Alibaba Cloud Product Pricing .
Let me mention here, the traffic fee on the ECS side is 0.8 yuan/GB , the link for details
OSS collects statistics on the usage of all OSS resources on an hourly basis, and settles fees based on usage.
Billing Case : Details Address
Mr. Li has stored 505GB standard storage (local redundancy) type files in OSS. The storage space is located in East China 1 (Hangzhou). The average number of requests per hour is 1,000 , and the daily outgoing traffic from the external network is about 2GB . Mr. Li can choose the following two options for payment:
> **Explain that** when OSS calculates the traffic cost, it is divided into busy hour traffic (8:00 24:00, 0.50 yuan/GB) and idle time traffic (00:00 08:00, 0.25 yuan/GB). Users use it during the day. It is calculated based on busy hour traffic.
- Total cost : about 91.32 yuan a month
Yearly and monthly + pay-as-you-go
> **Note** 5 GB of data beyond the storage package is billed on a per-use basis. > **illustrate** > > * Traffic is calculated as busy hour traffic. > * The 50 GB data package is only a half-yearly package, and the average monthly cost is 59.76 yuan / 6 months = 9.96 yuan.
- Total cost : about 70.28 yuan per month
List only core limits
|bandwidth||10 Gbit/s for all regions in mainland China and 5 Gbit/s for other regions. If this threshold is reached, the request will be flow-controlled. Note When the request is flow-controlled, it will be included in the header returned by the request
|Object or file (Object)||Upload file size
Upload a single file through simple upload , form upload , and additional upload , and the file size cannot exceed 5 GB. Upload a single file
through multipart upload , and the file size cannot exceed 48.8 TB.
Files with the same name are overwritten By default , if the uploaded file has the same name as an existing file, the existing file will be overwritten. To prevent the file from being accidentally overwritten, you can enable version control for the bucket where the file is located, or carry the parameter x-oss-forbid-overwrite in the Header of the upload request and specify its value as true.
|Domain name binding||Domain names bound to various regions in mainland China must be filed with the Ministry of Industry and Information Technology, and domain name bindings in other regions do not need to be filed with the Ministry of Industry and Information Technology. A domain name can only be bound to one storage space, and a storage space can be bound to a maximum of 100 domain names. There is no limit to the number of domain names that can be bound to an account.|
|Back-to-Origin Rules||A storage space can be configured with up to 20 back-to-origin rules. For mirrored back-to-source,
the default QPS of each region in Mainland China and Hong Kong is 2,000, and the traffic is 2 Gbit/s;
the default QPS of each overseas region is 1,000, and the traffic is 1 Gbit/s.
|image processing||Image restrictions The original image format only supports JPG, PNG, BMP, GIF, WebP, and TIFF. The original image size cannot exceed 20 MB.
The style limit can create a maximum of 50 styles per storage space
|resource pack||The regional resource pack only supports use in the home region; the mainland China general resource pack only supports the use in mainland China (excluding Hong Kong, China). The purchased resource pack does not support changing regions. Storage packs in resource packs do not support stacking purchases, but you can upgrade purchased storage packs . The transmission acceleration package and the back-to-source traffic package in the resource package support superimposed purchases, but upgrades and renewals are not supported. The downlink traffic package in the resource package supports superimposed purchase and renewal, but does not support upgrade. There is no corresponding resource package for the cross-region replication traffic fee in the request fee , data processing fee , and traffic fee .|
quick to use
1. Activate the service
If you want to further reduce OSS costs, it is recommended that you purchase [OSS resource packs] .
2. Create Bucket
A storage space (Bucket) is a container for storing objects (Object). Before uploading any type of Object, you need to create a Bucket.
Bucket name : Bucket name must be globally unique
Region : Bucket’s data center. Once a bucket is created, its region cannot be changed. To access OSS from ECS intranet, please select the same region as ECS
3. Test upload and access
test upload file
You can upload directly to the corresponding bucket, no screenshots
test access file
Note When accessing an image via a file URL, the default is to download . To ensure preview behavior when accessing images through file URLs, you need to bind a custom domain name and add a CNAME record. For details, see Binding a Custom Domain Name .
<dependency> <groupId>com.aliyun.oss</groupId> <artifactId>aliyun-sdk-oss</artifactId> <version>3.10.2</version> </dependency>
Go to the official maven repository yourself to see the latest version
2. Get AccessKey
AccessKey is abbreviated as AK, which refers to AccessKeyId and AccessKeySecret used in access authentication. OSS verifies the identity of the sender of a request by using AccessKeyId and AccessKeySecret symmetric encryption. AccessKeyId is used to identify the user; AccessKeySecret is the key used by the user to encrypt the signature string and OSS to verify the signature string, and must be kept secret.
3. Code example
// yourEndpoint fill in the Endpoint corresponding to the region where the Bucket is located. Taking China East 1 (Hangzhou) as an example, the Endpoint is filled in as https://oss-cn-hangzhou.aliyuncs.com. String endpoint = "yourEndpoint" ; // The Alibaba Cloud account AccessKey has access rights to all APIs, and the risk is high. It is strongly recommended that you create and use a RAM user for API access or daily operation and maintenance. Please log in to the RAM console to create a RAM user. String accessKeyId = "yourAccessKeyId" ; String accessKeySecret = "yourAccessKeySecret" ; // Create an OSSClient instance. OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); // Close OSSClient. ossClient.shutdown();
2. Upload file
// yourEndpoint fill in the Endpoint corresponding to the region where the Bucket is located. Taking China East 1 (Hangzhou) as an example, the Endpoint is filled in as https://oss-cn-hangzhou.aliyuncs.com. String endpoint = "yourEndpoint" ; // The Alibaba Cloud account AccessKey has access rights to all APIs, and the risk is high. It is strongly recommended that you create and use a RAM user for API access or daily operation and maintenance. Please log in to the RAM console to create a RAM user. String accessKeyId = "yourAccessKeyId" ; String accessKeySecret = "yourAccessKeySecret" ; // Create an OSSClient instance. OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); // Fill in the full path of the local file. If no local path is specified, the file stream will be uploaded from the local path corresponding to the project to which the sample program belongs by default. InputStream inputStream = new FileInputStream( "D:\\localpath\\examplefile.txt" ); // Fill in the Bucket name (for example, examplebucket) and the object's full path (for example, exampledir/exampleobject.txt) in turn. The bucket name cannot be included in the full path of Object. ossClient.putObject( "examplebucket" , "exampledir/exampleobject.txt" , inputStream); // Close OSSClient. ossClient.shutdown();
3. Get the post-upload address
"https://" + ossSetting.getBucketName() + "." + ossSetting.getEndPoint() + "/" + objectName;
Perform different operations on images stored in OSS, such as format conversion, cropping, scaling, rotation, watermarking, and style encapsulation.
- Original image : https://laker.oss-cn-hangzhou.aliyuncs.com/d1130961908d4c3681be7e878dc764a6.jpg
- Want to get its 400X400 picture : https://laker.oss-cn-hangzhou.aliyuncs.com/d1130961908d4c3681be7e878dc764a6.jpg?x-oss-process=style/400X400
Add ?x-oss-process=style/400X400, ?x-oss-process=style/200X200 at the end
To be in advance in the OSS console – data processing – new 400X400 style
When using image processing services, the following fees will be incurred:
Image processing fee
If the free quota is not exceeded, no fee will be incurred; after the free quota is exceeded, the fee will be charged according to the actual size of the original image processed.
Each account of the image processing service has a free quota of 10 TB per month, that is, when the original image processed per month does not exceed 10 TB, no image processing fee will be charged; when it exceeds 10 TB, only the excess fee will be calculated.
When processing an image, a GetObject request will be generated and charged per request.
Charges for outgoing traffic from the external network are charged according to the size of the original image processed.
It’s a bit of a pain to pay.
In the monitoring below, you can see which Referers steal our image traffic, close the small dark room for him, and set it directly on the console.
There are a lot of statistics in it, you can see if someone maliciously brushes our traffic, and you can close a small dark room for him.
1. How is OSS data organized?
OSS is a distributed object storage service that provides an object storage service in the form of Key-Value. When you store a file (Object), you need to specify the name (Key) of the object, and you will obtain the content of the object through this key later.
Key can also be used to simulate some properties of folders. The concept of a folder in OSS is only a logical concept. When setting a folder through the API or SDK, you can specify the key value corresponding to the Object including the previous directory to simulate the folder function. For example, defining the Object’s Key as , will create a folder
dir/example.jpgnamed under the current Bucket, and create a file named under the folder. If the user deletes it , the folder will no longer exist .