OssBodySegmentUtil.java 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //package com.fdkankan.scene.util;
  2. //
  3. //import cn.hutool.core.io.FileUtil;
  4. //import cn.hutool.http.HttpUtil;
  5. //import com.aliyun.imageseg20191230.models.SegmentBodyResponse;
  6. //import com.aliyun.oss.OSS;
  7. //import com.aliyun.oss.OSSClientBuilder;
  8. //import com.aliyun.tea.TeaException;
  9. //import com.fdkankan.common.util.FileUtils;
  10. //import com.fdkankan.scene.httpclient.MyClient;
  11. //import lombok.extern.slf4j.Slf4j;
  12. //import org.springframework.beans.factory.annotation.Autowired;
  13. //import org.springframework.beans.factory.annotation.Value;
  14. //import org.springframework.cloud.context.config.annotation.RefreshScope;
  15. //import org.springframework.stereotype.Component;
  16. //
  17. //import javax.annotation.Resource;
  18. //import java.io.File;
  19. //
  20. //@Slf4j
  21. //@Component
  22. //@RefreshScope
  23. //public class OssBodySegmentUtil {
  24. //
  25. // @Value("${oss.bodySegment.point:oss-cn-shanghai.aliyuncs.com}")
  26. // private String endPoint;
  27. //
  28. // @Value("${oss.bodySegment.imagesegPoint:imageseg.cn-shanghai.aliyuncs.com}")
  29. // private String imagesegEndPoint;
  30. //
  31. // @Value("${fyun.key}")
  32. // private String accessKeyId;
  33. //
  34. // @Value("${fyun.secret}")
  35. // private String accessKeySecret;
  36. //
  37. // @Value("${oss.bodySegment.bucket:4dkankan-huadong}")
  38. // private String bucket;
  39. //
  40. // @Resource
  41. // private MyClient myClient;
  42. //
  43. // public void uploadOss(String filePath, String key){
  44. // OSS ossClient = new OSSClientBuilder().build(endPoint, accessKeyId, accessKeySecret);
  45. // try {
  46. // File file = new File(filePath);
  47. // if (!file.exists()) {
  48. // log.error("要上传的文件不存在:" + filePath);
  49. // return;
  50. // }
  51. // ossClient.putObject(bucket, key, new File(filePath));
  52. // } catch (Exception e) {
  53. // log.error(e.toString() + filePath);
  54. // } finally {
  55. // ossClient.shutdown();
  56. // }
  57. // }
  58. //
  59. // public void extracted(String imageUrl, String dir, String fileName) throws Exception {
  60. // try {
  61. // com.aliyun.imageseg20191230.Client client = this.createClient();
  62. // com.aliyun.imageseg20191230.models.SegmentBodyRequest segmentBodyRequest =
  63. // new com.aliyun.imageseg20191230.models.SegmentBodyRequest().setImageURL(imageUrl);
  64. // com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
  65. // // 复制代码运行请自行打印 API 的返回值
  66. // SegmentBodyResponse segmentBodyResponse = client.segmentBodyWithOptions(segmentBodyRequest, runtime);
  67. // String imageURL = segmentBodyResponse.getBody().getData().getImageURL();
  68. // log.info("人体抠图imageURL:{}", imageURL);
  69. // myClient.downloadFile(imageURL, dir, fileName);
  70. // }catch (Exception e){
  71. // log.error("人体抠图失败,imageUrl:" + imageUrl, e);
  72. // myClient.downloadFile(imageUrl, dir, fileName);
  73. // }
  74. //
  75. // }
  76. //
  77. // public static void main(String[] args) {
  78. // FileUtils.downLoadFromUrl("http://vibktprfx-prod-prod-damo-eas-cn-shanghai.oss-cn-shanghai.aliyuncs.com/segment-body/2023-02-24/5d44fe44-308c-44c3-8e1d-2d4cbe601f86/image.png?Expires=1677208715&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=4ZyzaOz6W1nBD9s3KQuFN10c%2BPw%3D",
  79. // "1.png","D:\\test");
  80. // }
  81. //
  82. // /**
  83. // * 使用AK&SK初始化账号Client
  84. // * @return Client
  85. // * @throws Exception
  86. // */
  87. // public com.aliyun.imageseg20191230.Client createClient() throws Exception {
  88. // com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
  89. // // 必填,您的 AccessKey ID
  90. // .setAccessKeyId(accessKeyId)
  91. // // 必填,您的 AccessKey Secret
  92. // .setAccessKeySecret(accessKeySecret);
  93. // // 访问的域名
  94. // config.endpoint = this.imagesegEndPoint;
  95. // return new com.aliyun.imageseg20191230.Client(config);
  96. // }
  97. //
  98. //}