Alibaba Cloud OOS storage

OOS: Alibaba Cloud Object Storage OOS is a massive, secure, low-cost, and highly reliable cloud storage service that provides 99.99% data durability and availability. It has a variety of storage types to choose from and fully optimizes storage costs. It is very suitable for storing non-standard data. Structured data, such as videos, graphics, logs, text files and various app applications, multi-terminal synchronization software, files from network disk download sites, etc. The size of a single file ranges from 1 byte to 18.8TB, and the number of files that can be stored is unlimited. limit.

 

1. Register and log in, https://www.aliyun.com/ https://www.aliyun.com/

2. After successfully logging in (it is best to log in with Alipay), hover the mouse over 产品the area in the navigation bar of the main interface and enter 对象存储OSS;

3. Activate cloud storage, real-name authentication, and activate OOS.

4. Click the management console to enter. After entering the main interface of object storage, you will see an item in the overview Bucket列表, which is the place used to create a cloud storage folder. According to the process in the figure below, you will enter an 创建Bucketadd information column;

[Bucket name]: User-defined name [Region]: Custom selection [Storage type]: Standard storage [Redundant storage in the same city]: Turn off "Charge" [Version control]: Disable "Charge" [Read and write permissions]: Public reading [Server-side encryption method]: None [Real-time log query]: No "charge" enabled [Scheduled backup]: No "charge" enabled

 5. Enter the successfully set storage space and save it Bucket 域名; enter and view the save in the oss main interface Access Key. It will be used in the xml configuration later. Pay attention to the Bucket address and Access Key.

 6. Completing this step means that Alibaba Cloud OSS has been set up, and the next step is to write the backend!

Backend operations:

The pom file introduces dependencies:

 <!--阿里云oss依赖-->
        <dependency>
            <groupId>com.aliyun.oss</groupId>
            <artifactId>aliyun-sdk-oss</artifactId>
        </dependency>

 In the application.properties file, add the Bucket address and AccessKey configuration information for storing cloud storage.

# 端口号
server.port=8001
spring.application.name=yun-upload

# 环境地址
spring.profiles.active=dev

# 阿里云云存储OSS配置信息
# Bucket地址
aliyun.oss.file.endpoint=自定义
# Access Key
aliyun.oss.file.keyid=自定义
aliyun.oss.file.keysecret=自定义
# Bucket名称
aliyun.oss.file.bucketname=自定义

Utils class: used to read xml configuration information and convert the configuration information into tool classes for calling;

package com.csdn.oss.utils;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

//当项目已启动,spring接口,spring加载之后,执行接口一个方法
@Component
public class ConstantPropertiesUtils implements InitializingBean {

    //读取配置文件内容
    @Value("${aliyun.oss.file.endpoint}")
    private String endpoint;

    @Value("${aliyun.oss.file.keyid}")
    private String keyId;

    @Value("${aliyun.oss.file.keysecret}")
    private String keySecret;

    @Value("${aliyun.oss.file.bucketname}")
    private String bucketName;

    //定义公开静态常量
    public static String END_POIND;
    public static String ACCESS_KEY_ID;
    public static String ACCESS_KEY_SECRET;
    public static String BUCKET_NAME;

    @Override
    public void afterPropertiesSet() throws Exception {
        END_POIND = endpoint;
        ACCESS_KEY_ID = keyId;
        ACCESS_KEY_SECRET = keySecret;
        BUCKET_NAME = bucketName;
    }
}

service upload interface:

package com.csdn.oss.service;

import org.springframework.web.multipart.MultipartFile;

public interface OssService {
    //上传头像到oss
    String uploadFileAvatar(MultipartFile file);
}

serviceImpl: used to obtain uploaded files for judgment and processing;

package com.csdn.oss.service.impl;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.csdn.oss.service.OssService;
import com.csdn.oss.utils.ConstantPropertiesUtils;
import org.joda.time.DateTime;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.UUID;

@Service
public class OssServiceImpl implements OssService {

    //上传头像到oss
    @Override
    public String uploadFileAvatar(MultipartFile file) {
        // 工具类获取值
        String endpoint = ConstantPropertiesUtils.END_POIND;
        String accessKeyId = ConstantPropertiesUtils.ACCESS_KEY_ID;
        String accessKeySecret = ConstantPropertiesUtils.ACCESS_KEY_SECRET;
        String bucketName = ConstantPropertiesUtils.BUCKET_NAME;

        try {
            // 创建OSS实例。
                       OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

            //获取上传文件输入流
            InputStream inputStream = file.getInputStream();
            //获取文件名称
            String fileName = file.getOriginalFilename();

            //1 在文件名称里面添加随机唯一的值
            String uuid = UUID.randomUUID().toString().replaceAll("-","");
            // yuy76t5rew01.jpg
            fileName = uuid+fileName;

            //2 把文件按照日期进行分类
            //获取当前日期
            //   2019/11/12
            String datePath = new DateTime().toString("yyyy/MM/dd");
            //拼接
            //  2019/11/12/ewtqr313401.jpg
            fileName = datePath+"/"+fileName;

            //调用oss方法实现上传
            //第一个参数  Bucket名称
            //第二个参数  上传到oss文件路径和文件名称   aa/bb/1.jpg
            //第三个参数  上传文件输入流
            ossClient.putObject(bucketName,fileName , inputStream);

            // 关闭OSSClient。
            ossClient.shutdown();

            //把上传之后文件路径返回
            //需要把上传到阿里云oss路径手动拼接出来
            //  https://edu-guli-1010.oss-cn-beijing.aliyuncs.com/01.jpg
            String url = "https://"+bucketName+"."+endpoint+"/"+fileName;
            return url;
        }catch(Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

controller: returns the upload to the front end

package com.csdn.oss.controller;

import com.csdn.commonutils.R;
import com.csdn.oss.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/eduoss/fileoss")
@CrossOrigin
public class OssController {

    @Autowired
    private OssService ossService;

    //上传头像的方法
    @PostMapping
    public R uploadOssFile(MultipartFile file) {
        //获取上传文件  MultipartFile
        //返回上传到oss的路径
        String url = ossService.uploadFileAvatar(file);
        return R.ok().data("url",url);
    }
}

Test running code:

Open swagger-ui for testing: upload the file in swagger, and then check it on OOS 

Alibaba Cloud OOS security issues: Alibaba Cloud Object Storage OSS native DDoS protection capabilities - high-defense OSS function

        High-defense OSS, as the name suggests, is a native OSS instance with high-defense capabilities. High-defense OSS is a paid service launched when the OSS bucket suffers from high-traffic DDoS attacks and the service is unavailable. Users can configure high-defense OSS. Direct attack traffic targeting relevant buckets to high-defense IP to ensure the stability and reliability of the source bucket.

As the digital transformation of enterprises continues to deepen, more businesses are moving to the cloud, and a larger amount of business data is generated and used in order to better and better improve service quality. More industries adopt content-as-a-service architecture, and storage data flows directly to users and terminals. Against this background, the availability of storage platforms is crucial. At the same time, DDoS attacks are one of the most harmful attack methods to enterprise business in recent years. When an enterprise suffers a DDoS attack, it may cause business interruption, which in turn may lead to damage to the enterprise's image, loss of customers, loss of revenue, etc., seriously affecting the normal operation of the enterprise's business. To this end, OSS deeply integrates Alibaba Cloud DDoS Advanced Defense products to provide the highest T-level DDoS protection capabilities, million QPS protection, and second-level attack switching capabilities, which can effectively resist SYNFlood, ACKFlood, ICMPFlood, UDPFlood, NTPFlood, SSDPFlood, DNSFlood, HTTPFlood Waiting for attack. It is very suitable for scenarios where the business is often attacked by malicious attacks and affects the quality of service to achieve security protection. As a function of OSS products, High-Defense OSS is built on the OSS platform and provides one-stop OSS security (anti-attack) capabilities, aiming to provide native "security protection" services for users' cloud storage businesses. After a user activates high-defense OSS, when the user's Bucket is not attacked, the OSS standard domain name will be resolved to the native protection IP to maintain normal network status and ensure low business latency; when the user's Bucket is attacked, the relevant All access traffic will be given priority through the high-defense computer room. Malicious attack traffic will be cleaned and filtered in the high-defense traffic cleaning center. Normal access traffic will be returned to the OSS server through port protocol forwarding, thus ensuring that users can access normally when attacked. OSS.

1) Easy to deploy, easy to use, and imperceptible (native + high-defense dual protection)

Users only need to perform simple configuration on the OSS console to enjoy DDoS protection capabilities. After adding protection, you can exclusively use the cloud-native protection instance during the period when there are no attacks, maintaining normal network performance and ensuring no additional business delays; when under attack, OSS will automatically pass the bucket in the protection state through high-defense resources. The pool performs traffic cleaning to achieve automatic switching and maintain network service reliability.

2)T-level defense capability

The DDoS high defense capabilities based on Alibaba Cloud security products can provide up to T-level protection capabilities and have complete four- and seven-layer defense capabilities. In terms of traffic cleaning technology, for network traffic attacks and resource depletion DDoS attacks, through automatic optimization of protection algorithms and deep learning of business traffic baselines, we can accurately identify attack IPs and automatically filter and clean them.

3) DDoS protection engine is highly mature

From the perspective of application and practice, Alibaba Cloud Advanced Defense Engine has been used by tens of thousands of enterprise users. It has also withstood the test of extreme scenarios such as Double Eleven and World Cup live broadcast, and has accumulated rich protection experience and large resource reserves. It is widely used. , which can ensure the ultimate anti-attack capability for users’ business. From an architectural perspective, the DDoS protection engine uses a high-availability network protection cluster to avoid single points of failure and redundancy, and the processing performance supports elastic expansion. Fully automatic detection and attack strategy matching provide real-time protection, with cleaning service availability reaching 99.99%.

 

Guess you like

Origin blog.csdn.net/a154555/article/details/127345213