• 百度云文件上传调用记录、百度云上传


                sdk依赖  pom

            <dependency>
                <groupId>com.baidubce</groupId>
                <artifactId>bce-java-sdk</artifactId>
                <version>${bce-java-sdk.version}</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-log4j12</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

       service写法

    /**
     * 文件上传
     */
    @Service
    public class FileServiceImpl implements Fileservice {
        private static final String ENDPOINT = "fwh.bcebos.com";
        private static final String AK = "";
        private static final String SK = "";
        private static final String bucketName = "zy-test";
    
        private final BosClient client;
    
        public static void main(String[] args)throws  Exception {
            String s1 = FileBase64.encryptToBase64("D:\timg.png");
            System.out.println(s1);
        }
        public FileServiceImpl() {
            BosClientConfiguration config = new BosClientConfiguration();
            config.setCredentials(new DefaultBceCredentials(AK, SK));
            config.setEndpoint(ENDPOINT);
            config.setProtocol(Protocol.HTTPS);
            this.client = new BosClient(config);
        }

    尝试了各种编码的字符串以及字节数组上传都打不开  

     最后采用文件流进行上传的

            FileInputStream inputStream = new FileInputStream(filePath);
            PutObjectResponse putObjectResponseFromByte = client.putObject(bucketName, vo.getFileName(), inputStream);
            inputStream.close();
  • 相关阅读:
    cestos7安装zookeeper
    Cestos7安装Elasticsearch5.4.3
    debian使用nginx创建静态文件存储
    tomcat优化
    tomcat停止和启动脚本
    linux中shell变量$#,$@,$0,$1,$2的含义解释
    redis设置bind
    Jenkins send build artifacts over ssh配置
    nginx 负载均衡5种配置方式
    Jenkins tomcat打包启动脚本,待完善
  • 原文地址:https://www.cnblogs.com/qq376324789/p/13204346.html
Copyright © 2020-2023  润新知