/** * // Endpoint以杭州为例,其它Region请按实际情况填写。 String endpoint = "http://oss-cn-hangzhou.aliyuncs.com"; // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录RAM控制台创建RAM账号。 String accessKeyId = "<yourAccessKeyId>"; String accessKeySecret = "<yourAccessKeySecret>"; String bucketName = "<yourBucketName>"; // 创建OSSClient实例。 OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); final int maxKeys = 200; String nextMarker = null; ObjectListing objectListing; do { objectListing = ossClient.listObjects(new ListObjectsRequest(bucketName).withMarker(nextMarker).withMaxKeys(maxKeys)); List<OSSObjectSummary> sums = objectListing.getObjectSummaries(); for (OSSObjectSummary s : sums) { System.out.println(" " + s.getKey()); } nextMarker = objectListing.getNextMarker(); } while (objectListing.isTruncated()); // 关闭OSSClient。 ossClient.shutdown(); */ 参考网址:https://help.aliyun.com/document_detail/84841.html?spm=5176.11065259.1996646101.searchclickresult.7e1a7b57qlFzAR
示例代码: private void GetFileAllContentPA(String str) { OSS ossClient = new OSSClientBuilder().build(endPoint, accessKey, accessSecret); final int maxKeys = 200; String nextMarker = null; ObjectListing objectListing; do { objectListing = ossClient.listObjects( new ListObjectsRequest(bucketName).withPrefix(str).withMarker(nextMarker).withMaxKeys(maxKeys)); List<OSSObjectSummary> sums = objectListing.getObjectSummaries(); for (OSSObjectSummary s : sums) { boolean flag = Pattern.matches(CommonConstant.REGEX, (s.getKey().split(CommonConstant.PATH_SYMBOL)[CommonConstant.FILE_PATH_INDEX])); if (!flag) { if (s.getKey().endsWith(CommonConstant.TRANS_NO_PDF)) { String trans = s.getKey().substring(s.getKey().lastIndexOf(CommonConstant.PATH_SYMBOL) + 1); log.info("============" + s.getKey()); ossUtils.CreateConnection(trans.substring(CommonConstant.TRANS_NO_INDEX, CommonConstant.TRANS_NO_LONG), s.getKey()); ReceiptRecord receiptRecord =new ReceiptRecord(); receiptRecord.setTransNo(trans.substring(CommonConstant.TRANS_NO_INDEX, CommonConstant.TRANS_NO_LONG)); receiptRecord.setFilePath( s.getKey()); receiptRecord.setCreateDate(new Date());; pingAnService.insertRecord(receiptRecord); } } } nextMarker = objectListing.getNextMarker(); } while (objectListing.isTruncated()); // 关闭OSSClient。 ossClient.shutdown(); }