@Override protected Bitmap doInBackground(Object... params) { iv = (ImageView) params[0]; thumbnailPath = (String) params[1]; localFullSizePath = (String) params[2]; ctx = (Context) params[3]; remotePath = (String) params[4]; Bitmap result = ImageUtils.decodeScaleImage(localFullSizePath, 160, 160); if (result == null && remotePath != null) { OSSData avatar = OssManager.getInstance().downLoadData(remotePath); try { byte[] data = avatar.get(); if (data != null) { result = BitmapFactory.decodeByteArray(data, 0, data.length); ImageCache.getInstance().put(localFullSizePath, result); result = ImageUtils.decodeScaleImage(localFullSizePath, 160, 160); } } catch (OSSException e) { e.printStackTrace(); return null; } } return result; }
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; }