public void uploadImg( String dirType, String userId, String fileName, Bitmap bitmap, final ChatCallBack callback, boolean compress, String bucketName) { OSSBucket mBucket = ossService.getOssBucket(bucketName); OSSData ossData = ossService.getOssData(mBucket, userId + "/" + dirType + "/" + fileName); if (compress && bitmap.getByteCount() > 1024 * 100) ossData.setData(ImageUtils.bitmap2Bytes(bitmap, true), "img"); // 指定需要上传的数据和它的类型 else ossData.setData(ImageUtils.bitmap2Bytes(bitmap, false), "img"); ossData.enableUploadCheckMd5sum(); // 开启上传MD5校验 ossData.uploadInBackground( new SaveCallback() { @Override public void onSuccess(String objectKey) { LogUtil.info(ChatManager.class, objectKey); callback.onSuccess(); callback.onSuccess(objectKey); } @Override public void onProgress(String objectKey, int byteCount, int totalSize) { callback.onProgress(byteCount, totalSize); } @Override public void onFailure(String objectKey, OSSException ossException) { callback.onError(ChatManager.ERROR_OSS, ossException.getMessage()); } }); }
public OSSData uploadData(String uuid, String dirType, String fileName, byte[] data) { OSSBucket mBucket = ossService.getOssBucket("userfile-aotobang"); OSSData ossData = ossService.getOssData(mBucket, uuid + "/" + dirType + "/" + fileName); ossData.setData(data, "img"); // 指定需要上传的数据和它的类型 ossData.enableUploadCheckMd5sum(); // 开启上传MD5校验 return ossData; }