腾讯云COS直传,官方后端demo,GO写的,我们台是JAVA所以转一下,已跑通。废话不多说,直接上代码:
Controller类如下:
import com.ruoyi.web.core.config.CosConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
@RestController
@CrossOrigin(origins = "http://127.0.0.1:8080", allowedHeaders = "origin,accept,content-type")
@RequestMapping
public class CosController {
@Autowired
private CosConfig config;
@GetMapping("/post-policy")
public ResponseEntity<Map<String, Object>> getPostPolicy(@RequestParam String ext) {
// 判断异常情况
if (config.getSecretId() == null || config.getSecretKey() == null) {
return buildErrorResponse("-1", "secretId or secretKey not ready");
}
if (config.getBucket() == null || config.getR