|
@@ -77,9 +77,11 @@ public class UploadHelper implements View.OnClickListener {
|
|
|
private CosXmlSimpleService mCosXmlService;
|
|
|
private COSXMLUploadTask cosxmlUploadTask;
|
|
|
private boolean isCancel = false;
|
|
|
+ private int businessType = -1;
|
|
|
|
|
|
public UploadHelper(Activity activity, int type) {
|
|
|
this(activity, UploadConstants.getBucketNameByType(type), UploadConstants.getPathByType(type));
|
|
|
+ this.businessType = type;
|
|
|
}
|
|
|
|
|
|
public UploadHelper(Activity activity, String path) {
|
|
@@ -271,20 +273,48 @@ public class UploadHelper implements View.OnClickListener {
|
|
|
return;
|
|
|
}
|
|
|
String name = FileUtils.getFileName(file);
|
|
|
- long timeStr = TimeUtils.getNowMills();
|
|
|
- if (name.contains(".")) {
|
|
|
- String[] split = name.split("\\.");
|
|
|
- name = timeStr + "." + split[split.length - 1];
|
|
|
- } else {
|
|
|
- name = "" + timeStr;
|
|
|
- }
|
|
|
- String lastName = getUserId() + "_" + name;
|
|
|
- String month = TimeUtils.date2String(TimeUtils.getNowDate(), TimeUtils.getSafeDateFormat("yyyy-MM"));
|
|
|
- String key = formatPath(path) + "android/" + month + "/" + lastName;
|
|
|
+ String key = getKey(name);
|
|
|
isCancel = false;
|
|
|
getUploadToken(name, key, file);
|
|
|
}
|
|
|
|
|
|
+ private String getKey(String name) {
|
|
|
+ String lastName = getLastName(name);
|
|
|
+ String month = TimeUtils.date2String(TimeUtils.getNowDate(), TimeUtils.getSafeDateFormat("yyyy-MM"));
|
|
|
+ String key;
|
|
|
+ if (businessType == UploadConstants.UPLOAD_TYPE_AVATAR) {
|
|
|
+ //头像
|
|
|
+ key = formatPath(path) + "avatar/" + lastName;
|
|
|
+ } else {
|
|
|
+ key = formatPath(path) + "android/" + month + "/" + lastName;
|
|
|
+ }
|
|
|
+ return key;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getLastName(String name) {
|
|
|
+ String lastName;
|
|
|
+ if (businessType == UploadConstants.UPLOAD_TYPE_AVATAR) {
|
|
|
+ //头像类型需要固定名称
|
|
|
+ if (name.contains(".")) {
|
|
|
+ String[] split = name.split("\\.");
|
|
|
+ lastName = getUserId() + "." + split[split.length - 1];
|
|
|
+ } else {
|
|
|
+ long timeStr = TimeUtils.getNowMills();
|
|
|
+ lastName = getUserId() + "_" + timeStr;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ long timeStr = TimeUtils.getNowMills();
|
|
|
+ if (name.contains(".")) {
|
|
|
+ String[] split = name.split("\\.");
|
|
|
+ name = timeStr + "." + split[split.length - 1];
|
|
|
+ } else {
|
|
|
+ name = "" + timeStr;
|
|
|
+ }
|
|
|
+ lastName = getUserId() + "_" + name;
|
|
|
+ }
|
|
|
+ return lastName;
|
|
|
+ }
|
|
|
+
|
|
|
private String formatPath(String path) {
|
|
|
if (TextUtils.isEmpty(path)) {
|
|
|
return "";
|
|
@@ -394,7 +424,7 @@ public class UploadHelper implements View.OnClickListener {
|
|
|
}
|
|
|
|
|
|
private void cancelUpload() {
|
|
|
- this.isCancel =true;
|
|
|
+ this.isCancel = true;
|
|
|
if (cosxmlUploadTask != null) {
|
|
|
cosxmlUploadTask.cancel();
|
|
|
}
|