Skip to content

Commit 152f16a

Browse files
committed
fixed: mime_type is null for special external url within AVFile
1 parent de8a6e0 commit 152f16a

File tree

8 files changed

+119
-16
lines changed

8 files changed

+119
-16
lines changed

android-sdk/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ allprojects {
3030
}
3131

3232
ext {
33-
sdkVersion = "6.5.10"
33+
sdkVersion = "6.5.11"
3434
supportLibVersion = "26.1.0"
3535
converterVersion = "2.1.0"
3636
rxandroidVersion = "2.1.1"

android-sdk/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ org.gradle.jvmargs=-Xmx1536m
1515
# This option should only be used with decoupled projects. More details, visit
1616
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1717
# org.gradle.parallel=true
18-
VERSION_NAME=6.5.10
18+
VERSION_NAME=6.5.11
1919
VERSION_CODE=2695
2020
GROUP=cn.leancloud
2121

android-sdk/realtime-sample-app/src/main/java/cn/leancloud/realtime_sample_app/MainActivity.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import android.widget.TextView;
1414

1515
import java.util.Arrays;
16+
import java.util.HashMap;
1617
import java.util.List;
1718
import java.util.stream.Collectors;
1819

@@ -233,17 +234,21 @@ public void done(AVException e) {
233234
case R.id.navigation_notifications:
234235
mTextMessage.setText(R.string.title_notifications);
235236
try {
236-
AVIMAudioMessage audioMessage = new AVIMAudioMessage(MainActivity.this.getCacheDir().getAbsolutePath() + "/dYRQ8YfHavfile/c1fa842a72de9129f5b2b342cbeb3c9d");
237+
AVFile file = new AVFile("apple.acc", "https://some.website.com/apple.acc", new HashMap<>());
238+
AVIMAudioMessage m = new AVIMAudioMessage(file);
239+
m.setText("来自苹果发布会现场的录音");
240+
// AVIMAudioMessage audioMessage = new AVIMAudioMessage(MainActivity.this.getCacheDir().getAbsolutePath() + "/dYRQ8YfHavfile/c1fa842a72de9129f5b2b342cbeb3c9d");
237241
currentClient.createTemporaryConversation(Arrays.asList("abc", "def"), new AVIMConversationCreatedCallback() {
238242
@Override
239243
public void done(AVIMConversation conversation, AVIMException e) {
240244
if (e != null) {
241245
Log.e("tag", "failed to create conversations. error ", e);
242246
} else {
243-
conversation.sendMessage(audioMessage, new AVIMConversationCallback() {
247+
conversation.sendMessage(m, new AVIMConversationCallback() {
244248
@Override
245249
public void done(AVIMException ex) {
246250
if (null != ex) {
251+
ex.printStackTrace();
247252
Log.e("tag", "failed to send Audio Message, cause: " + ex.getMessage());
248253
} else {
249254
Log.d("tag", "succeed to send audio message.");

core/src/main/java/cn/leancloud/AVFile.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.concurrent.Callable;
2222

2323
import cn.leancloud.upload.*;
24+
import cn.leancloud.utils.AVUtils;
2425
import cn.leancloud.utils.FileUtil;
2526
import cn.leancloud.utils.StringUtil;
2627
import com.alibaba.fastjson.JSONObject;
@@ -95,7 +96,6 @@ public AVFile(String name, byte[] data) {
9596
addMetaData(FILE_SUM_KEY, md5);
9697
addMetaData(FILE_LENGTH_KEY, data.length);
9798
internalPut(KEY_MIME_TYPE, FileUtil.getMimeTypeFromFilename(name));
98-
logger.d("localpath=" + localPath);
9999
}
100100

101101
/**
@@ -144,7 +144,7 @@ protected AVFile(String name, String url, Map<String, Object> metaData, boolean
144144
internalPut(KEY_URL, url);
145145
Map<String, Object> meta = new HashMap<String, Object>();
146146
if (null != metaData) {
147-
meta.putAll(metaData);
147+
AVUtils.putAllWithNullFilter(meta, metaData);
148148
}
149149
if (external) {
150150
meta.put(FILE_SOURCE_KEY, FILE_SOURCE_EXTERNAL);
@@ -487,7 +487,7 @@ private Observable<AVFile> directlyCreate(final JSONObject parameters) {
487487
.map(new Function<AVObject, AVFile>() {
488488
@Override
489489
public AVFile apply(AVObject avObject) throws Exception {
490-
AVFile.this.serverData.putAll(parameters);
490+
AVUtils.putAllWithNullFilter(AVFile.this.serverData, parameters);
491491
AVFile.this.mergeRawData(avObject, true);
492492
AVFile.this.onSaveSuccess();
493493
return AVFile.this;

core/src/main/java/cn/leancloud/utils/AVUtils.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public static Map<String, Object> createMap(String cmp, Object value) {
4545

4646
public static Map<String, Object> createStringObjectMap(String key, Object value) {
4747
Map<String, Object> map = new HashMap<String, Object>();
48-
map.put(key, value);
48+
if (null != value) {
49+
map.put(key, value);
50+
}
4951
return map;
5052
}
5153

@@ -111,4 +113,15 @@ public static void mergeConcurrentMap(ConcurrentMap<String, Object> left, Map<St
111113
left.put(entry.getKey(), entry.getValue());
112114
}
113115
}
116+
117+
public static void putAllWithNullFilter(Map<String, Object> source, Map<String, Object> dest) {
118+
if (null == source || null == dest) {
119+
return;
120+
}
121+
for (Map.Entry<String, Object> e: dest.entrySet()) {
122+
if (null != e.getValue()) {
123+
source.put(e.getKey(), e.getValue());
124+
}
125+
}
126+
}
114127
}

core/src/main/java/cn/leancloud/utils/FileUtil.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,24 @@ public static String getFileMimeType(AVFile avFile) {
6161
public static String getMimeTypeFromFilename(String fileName) {
6262
String extension = getExtensionFromFilename(fileName);
6363
if (!StringUtil.isEmpty(extension)) {
64-
return detector.getMimeTypeFromExtension(extension);
64+
String result = detector.getMimeTypeFromExtension(extension);
65+
return null != result? result : "";
6566
}
6667
return "";
6768
}
6869

6970
public static String getMimeTypeFromPath(String localPath) {
7071
if (!StringUtil.isEmpty(localPath)) {
71-
return detector.getMimeTypeFromPath(localPath);
72+
String result = detector.getMimeTypeFromPath(localPath);
73+
return null != result? result : "";
7274
}
7375
return "";
7476
}
7577

7678
public static String getMimeTypeFromUrl(String url) {
7779
if (!StringUtil.isEmpty(url)) {
78-
return detector.getMimeTypeFromUrl(url);
80+
String result = detector.getMimeTypeFromUrl(url);
81+
return null != result? result : "";
7982
}
8083
return "";
8184
}

core/src/test/java/cn/leancloud/AVFileTest.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.reactivex.Observable;
66
import io.reactivex.Observer;
77
import io.reactivex.disposables.Disposable;
8+
import io.reactivex.schedulers.Schedulers;
89
import junit.framework.Test;
910
import junit.framework.TestCase;
1011
import junit.framework.TestSuite;
@@ -252,7 +253,7 @@ public void onComplete() {
252253

253254
public void testExternalFile2() throws Exception {
254255
String url = "http://i1.wp.com/blog.avoscloud.com/wp-content/uploads/2014/05/screen568x568-1.jpg?resize=202%2C360";
255-
AVFile file = new AVFile("screen.jpg", url);
256+
AVFile file = new AVFile("screen.jpg", url, null);
256257
file.saveInBackground().subscribe(new Observer<AVFile>() {
257258
@Override
258259
public void onSubscribe(Disposable disposable) {
@@ -261,6 +262,40 @@ public void onSubscribe(Disposable disposable) {
261262

262263
@Override
263264
public void onNext(AVFile avFile) {
265+
System.out.println(avFile.toJSONString());
266+
testSucceed = true;
267+
latch.countDown();
268+
}
269+
270+
@Override
271+
public void onError(Throwable throwable) {
272+
throwable.printStackTrace();
273+
latch.countDown();
274+
}
275+
276+
@Override
277+
public void onComplete() {
278+
279+
}
280+
});
281+
latch.await();
282+
assertTrue(testSucceed);
283+
}
284+
285+
public void testExternalFile3() throws Exception {
286+
String url = "https://some.website.com/apple.acc";
287+
AVFile file = new AVFile("screen.jpg", url, null);
288+
file.saveInBackground(true)
289+
.subscribeOn(Schedulers.io())
290+
.subscribe(new Observer<AVFile>() {
291+
@Override
292+
public void onSubscribe(Disposable disposable) {
293+
294+
}
295+
296+
@Override
297+
public void onNext(AVFile avFile) {
298+
System.out.println(avFile.toJSONString());
264299
testSucceed = true;
265300
latch.countDown();
266301
}

realtime/src/test/java/cn/leancloud/im/AVIMClientTest.java

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package cn.leancloud.im;
22

3-
import cn.leancloud.AVLogger;
4-
import cn.leancloud.AVQuery;
5-
import cn.leancloud.AVUser;
6-
import cn.leancloud.Configure;
3+
import cn.leancloud.*;
74
import cn.leancloud.core.AVOSCloud;
85
import cn.leancloud.im.v2.AVIMClient;
96
import cn.leancloud.im.v2.AVIMConversation;
107
import cn.leancloud.im.v2.AVIMConversationsQuery;
118
import cn.leancloud.im.v2.AVIMException;
129
import cn.leancloud.im.v2.callback.*;
1310
import cn.leancloud.im.v2.conversation.AVIMConversationMemberInfo;
11+
import cn.leancloud.im.v2.messages.AVIMAudioMessage;
1412
import cn.leancloud.session.AVConnectionManager;
1513
import cn.leancloud.utils.StringUtil;
1614
import junit.framework.TestCase;
@@ -370,6 +368,55 @@ public void done(List<AVIMConversationMemberInfo> memberInfoList, AVIMException
370368
assertTrue(opersationSucceed);
371369
}
372370

371+
public void testSendAudioMessageInTempConv() throws Exception {
372+
final AVIMClient client = AVIMClient.getInstance("testUser1");
373+
Thread.sleep(4000);
374+
client.open(new AVIMClientCallback() {
375+
@Override
376+
public void done(AVIMClient client, AVIMException e) {
377+
if (null != e) {
378+
System.out.println("failed open client.");
379+
e.printStackTrace();
380+
countDownLatch.countDown();
381+
} else {
382+
System.out.println("succeed open client.");
383+
client.createTemporaryConversation(Arrays.asList("testUser2"),
384+
new AVIMConversationCreatedCallback() {
385+
@Override
386+
public void done(AVIMConversation conversation, AVIMException ex) {
387+
if (null != ex) {
388+
System.out.println("failed to create temp Conv");
389+
ex.printStackTrace();
390+
countDownLatch.countDown();
391+
} else {
392+
System.out.println("succeed to create temp Conv");
393+
AVFile file = new AVFile("apple.acc", "https://some.website.com/apple.acc", null);
394+
AVIMAudioMessage m = new AVIMAudioMessage(file);
395+
m.setText("来自苹果发布会现场的录音");
396+
conversation.sendMessage(m, new AVIMConversationCallback() {
397+
@Override
398+
public void done(AVIMException e3) {
399+
if (null != e3) {
400+
System.out.println("failed to send audio message.");
401+
e3.printStackTrace();
402+
} else {
403+
System.out.println("succeed to send audio message.");
404+
opersationSucceed = true;
405+
}
406+
countDownLatch.countDown();
407+
}
408+
});
409+
}
410+
}
411+
});
412+
}
413+
}
414+
});
415+
countDownLatch.await();
416+
client.close(null);
417+
assertTrue(opersationSucceed);
418+
}
419+
373420
public void testGetConversations() throws Exception {
374421
final AVIMClient client = AVIMClient.getInstance("testUser1");
375422
Thread.sleep(4000);

0 commit comments

Comments
 (0)