1 package com.netease.nimlib.sdk.v2.utils;
3 import android.text.TextUtils;
34 if(fileAttachment == null){
38 if(TextUtils.isEmpty(path) || !(
new File(path).exists())) {
41 if(TextUtils.isEmpty(path)){
44 return new File(path).exists() ? path : null;
53 if(fileAttachment == null){
56 String path = fileAttachment.
getPath();
57 if (!TextUtils.isEmpty(path)) {
71 if(fileAttachment == null){
74 String path = fileAttachment.
getPath();
75 if (!TextUtils.isEmpty(path)) {
78 String fileName = getFileName(fileAttachment);
79 if(TextUtils.isEmpty(fileName)){
82 return NimStorageUtil.getWritePath(fileName, storageType(fileAttachment));
92 if(fileAttachment == null){
96 if(TextUtils.isEmpty(path) || !(
new File(path).exists())) {
99 if(TextUtils.isEmpty(path)){
102 return new File(path).exists() ? path : null;
111 if(fileAttachment == null){
124 if(fileAttachment == null){
127 String fileName = getFileName(fileAttachment);
128 if (!TextUtils.isEmpty(fileName)) {
129 int dotIndex = fileName.lastIndexOf(
".");
131 if (dotIndex >= 0 && dotIndex < fileName.length() - 1) {
132 fileName = fileName.substring(0, dotIndex);
137 return NimStorageUtil.getWritePath(fileName, NimStorageType.TYPE_THUMB_IMAGE);
141 if(fileAttachment == null){
144 String md5 = fileAttachment.
getMd5();
145 if (TextUtils.isEmpty(md5)) {
146 md5 = MD5.getStringMD5(fileAttachment.
getUrl());
148 return md5 != null ? md5 :
"";
153 return NimStorageType.TYPE_AUDIO;
155 return NimStorageType.TYPE_IMAGE;
157 return NimStorageType.TYPE_VIDEO;
159 return NimStorageType.TYPE_FILE;
166 switch (downloadType) {
168 case V2NIM_DOWNLOAD_ATTACHMENT_TYPE_THUMBNAIL:
169 case V2NIM_DOWNLOAD_ATTACHMENT_TYPE_VIDEO_COVER:
173 case V2NIM_DOWNLOAD_ATTACHMENT_TYPE_SOURCE:
175 ext = attachment == null ?
"" : attachment.
getExt();
180 if (StringUtil.isEmpty(ext))
184 if (ext.startsWith(
"."))
186 ext = ext.substring(1);
192 if (fileAttachment == null) {
195 String md5 = fileAttachment.
getMd5();
196 if (StringUtil.isEmpty(md5)) {
199 String fileName =
"" + (md5) +
"." + (ext);
201 fileName =
"thumb_" + (fileName);
203 return NimStorageUtil.getWritePath(fileName, storageType(fileAttachment));
V2NIM_DOWNLOAD_ATTACHMENT_TYPE_THUMBNAIL
图片缩略图,仅支持图片类附件
static String getFileAttachmentPath(V2NIMMessageFileAttachment fileAttachment)
获取文件路径
static String getFileAttachmentStoragePath(V2NIMMessageFileAttachment fileAttachment)
获取文件存储路径,和V1逻辑保持一致
static String getDownloadAttachmentDefaultThumbStoragePath(V2NIMMessageFileAttachment fileAttachment)
获取V2NIMStorageService#downloadAttachment的缩略图默认存储路径
V2NIM_DOWNLOAD_ATTACHMENT_TYPE_SOURCE
原始资源,支持全部有附件的类型
static String getDownloadAttachmentDefaultStoragePath(V2NIMMessageFileAttachment fileAttachment)
获取V2NIMStorageService#downloadAttachment的默认存储路径
static String getFileAttachmentThumbPath(V2NIMMessageFileAttachment fileAttachment)
获取文件缩略图路径,和V1逻辑保持一致
static String getFileAttachmentThumbStoragePath(V2NIMMessageFileAttachment fileAttachment)
获取文件缩略图存储路径,和V1逻辑保持一致