package com.example.aliossjava.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.aliossjava.common.UploadUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


@RestController
public class UploadController {
    /*
     * @RequestMapping 路由映射的注解
     * */
    @RequestMapping(value = "/uploadfile",method = RequestMethod.POST)
    public boolean myGetList(@RequestBody @Valid String a){
        try {
            System.out.println(a);
            JSONObject jsonObject = JSONObject.parseObject(a);
            String ossurl=jsonObject.getString("ossurl");
            String filedir=jsonObject.getString("filedir");
            String objectName=jsonObject.getString("objectName");
            String encodePolicy=jsonObject.getString("encodePolicy");
            String signature=jsonObject.getString("signature");
            String endpoint=jsonObject.getString("endpoint");
            String accessKeyId=jsonObject.getString("accessKeyId");
            String bucketName=jsonObject.getString("bucketName");
            UploadUtils UploadUtils =new UploadUtils();
            UploadUtils.doUpload(ossurl,endpoint,accessKeyId,bucketName,filedir,objectName,encodePolicy,signature);
            return true;
        } catch (Exception e) {
            System.out.println("uploadfile-error："+e.toString());
            return false;
        }
    }
}
