java.lang.RuntimeException: Unsupported algorithm: HmacSHA1-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

java.lang.RuntimeException: Unsupported algorithm: HmacSHA1

qschain 2016-10-21 15:30:50 2701

QQ_20161021152651

try {
            OSSClient client = new OSSClient(END_POINT, ACCESS_ID, ACCESS_KEY);
            System.out.println("come to create bucket name");
            boolean exist = client.doesBucketExist(BUCKETNAME);  
            System.out.println("exist is: "+exist);
            if (!exist) {  
                client.createBucket(BUCKETNAME);
            }  
            BucketInfo bucketInfo = client.getBucketInfo(BUCKETNAME);
            System.out.println("================================bucketInfo: "+bucketInfo);
//            //设置bucket的访问权限,public-read-write权限
//            client.setBucketAcl(BUCKETNAME, CannedAccessControlList.PublicRead);
            
            ByteArrayOutputStream out = new ByteArrayOutputStream();// 先读入内存
            byte[] b = new byte[512];
            int len;
            while ((len = is.read(b)) != -1) {
                out.write(b, 0, len);
            }
            
            String key = MD5Util.getMD5String(out.toByteArray());
            
            ObjectMetadata objectMeta = new ObjectMetadata();
            objectMeta.setContentLength(out.size());
            // 可以在metadata中标记文件类型
            if (StringUtils.isEmpty(name)) {
                name = "temp.png";
            }
            if(name.toLowerCase().contains(".png")) {
                objectMeta.setContentType("image/png");
                key += ".png";
            }else if(name.toLowerCase().contains(".gif")) {
                objectMeta.setContentType("image/gif");
                key += ".gif";
            }else {
                objectMeta.setContentType("image/jpeg");
                key += ".jpg";
            }

            
//            InputStream in = new ByteArrayInputStream(out.toByteArray());
            
            PutObjectResult result = client.putObject(BUCKETNAME, key, is, objectMeta);
//            System.out.println("result: "+result);
//            System.out.println("key: "+key);
            client.shutdown();
            if(result!=null){
                return key;
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
        } finally{
            if(is != null){
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
Java
分享到
取消 提交回答
全部回答(2)
添加回答
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

推荐文章
相似问题
推荐课程