百度云文件上传调用记录、百度云上传
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();