Skip to content

Commit 5a2d0e8

Browse files
authored
Merge pull request #543 from GetStream/fix-expo-image-upload
CRNS-270: Fix image upload for expo and assets-library
2 parents f3b2d21 + 64bc484 commit 5a2d0e8

File tree

8 files changed

+197
-63
lines changed

8 files changed

+197
-63
lines changed

examples/ExpoMessaging/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
"expo-document-picker": "8.4.1",
1818
"expo-file-system": "9.3.0",
1919
"expo-haptics": "8.4.0",
20-
"expo-image-picker": "9.2.0",
20+
"expo-image-picker": "10.0.0",
2121
"expo-image-manipulator": "9.0.0",
22-
"expo-media-library": "10.0.0",
23-
"expo-permissions": "10.0.0",
22+
"expo-media-library": "11.0.0",
23+
"expo-permissions": "11.0.0",
2424
"expo-sharing": "8.5.0",
2525
"react": "16.13.1",
2626
"react-dom": "16.13.1",

examples/ExpoMessaging/yarn.lock

Lines changed: 104 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -976,13 +976,20 @@
976976
dependencies:
977977
regenerator-runtime "^0.13.4"
978978

979-
"@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.12.0", "@babel/runtime@^7.12.5", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.4":
979+
"@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.12.0", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.4":
980980
version "7.12.5"
981981
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.12.5.tgz#410e7e487441e1b360c29be715d870d9b985882e"
982982
integrity sha512-plcc+hbExy3McchJCEQG3knOsuh3HH+Prx1P6cLIkET/0dLuQDEnrT+s27Axgc9bqfsmNUNHfscgMUdBpC9xfg==
983983
dependencies:
984984
regenerator-runtime "^0.13.4"
985985

986+
"@babel/runtime@^7.12.13":
987+
version "7.13.9"
988+
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.13.9.tgz#97dbe2116e2630c489f22e0656decd60aaa1fcee"
989+
integrity sha512-aY2kU+xgJ3dJ1eU6FMB9EH8dIe8dmusF1xEku52joLvw6eAFN0AI+WxCLDnpev2LEejWBAy2sBvBOBAjI3zmvA==
990+
dependencies:
991+
regenerator-runtime "^0.13.4"
992+
986993
"@babel/template@^7.0.0", "@babel/template@^7.10.4", "@babel/template@^7.12.7", "@babel/template@^7.8.6":
987994
version "7.12.7"
988995
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.12.7.tgz#c817233696018e39fbb6c491d2fb684e05ed43bc"
@@ -1063,6 +1070,26 @@
10631070
xcode "^2.1.0"
10641071
xml2js "^0.4.23"
10651072

1073+
"@expo/config-plugins@~1.0.13":
1074+
version "1.0.20"
1075+
resolved "https://registry.yarnpkg.com/@expo/config-plugins/-/config-plugins-1.0.20.tgz#b1964daf063d7ce07c3f135aa92ccf1c60cd6e46"
1076+
integrity sha512-BucZQbi7edu8Pin8zFUNsaQeZAj/8ga7Ei3PKivKZKd5F53DdFU6Yb+ZDyQ0UeOGDi0hZlZWdaBzmQqHEg37TQ==
1077+
dependencies:
1078+
"@expo/config-types" "^40.0.0-beta.2"
1079+
"@expo/configure-splash-screen" "0.3.4"
1080+
"@expo/image-utils" "0.3.10"
1081+
"@expo/json-file" "8.2.28-alpha.0"
1082+
"@expo/plist" "0.0.11"
1083+
find-up "~5.0.0"
1084+
fs-extra "9.0.0"
1085+
getenv "0.7.0"
1086+
glob "7.1.6"
1087+
resolve-from "^5.0.0"
1088+
slash "^3.0.0"
1089+
slugify "^1.3.4"
1090+
xcode "^2.1.0"
1091+
xml2js "^0.4.23"
1092+
10661093
"@expo/config-types@^40.0.0-beta.2":
10671094
version "40.0.0-beta.2"
10681095
resolved "https://registry.yarnpkg.com/@expo/config-types/-/config-types-40.0.0-beta.2.tgz#4fea4ef5654d02218b02b0b3772529a9ce5b0471"
@@ -1103,6 +1130,22 @@
11031130
xcode "^3.0.0"
11041131
xml-js "^1.6.11"
11051132

1133+
1134+
version "0.3.4"
1135+
resolved "https://registry.yarnpkg.com/@expo/configure-splash-screen/-/configure-splash-screen-0.3.4.tgz#b91d8f08fd96272bd3d7aaa9b51d6189b932c7cc"
1136+
integrity sha512-HsukM03X5/EXSucVsLN/oLqyFq/1jAjpADkgU1HLaezFpkr+TOquI6yDwdDp1450kcm891PE/SYJ+mCdPxzDLw==
1137+
dependencies:
1138+
color-string "^1.5.3"
1139+
commander "^5.1.0"
1140+
core-js "^3.6.5"
1141+
deep-equal "^2.0.3"
1142+
fs-extra "^9.0.0"
1143+
glob "^7.1.6"
1144+
lodash "^4.17.15"
1145+
pngjs "^5.0.0"
1146+
xcode "^3.0.0"
1147+
xml-js "^1.6.11"
1148+
11061149
11071150
version "0.3.10"
11081151
resolved "https://registry.yarnpkg.com/@expo/image-utils/-/image-utils-0.3.10.tgz#bdb9d6a2a7280680dd56d7f9dd283863b58d1e1e"
@@ -1131,6 +1174,16 @@
11311174
lodash "^4.17.15"
11321175
write-file-atomic "^2.3.0"
11331176

1177+
1178+
version "8.2.28-alpha.0"
1179+
resolved "https://registry.yarnpkg.com/@expo/json-file/-/json-file-8.2.28-alpha.0.tgz#0e5280c82a17165be12c6a95cd95ec108c6dfe7b"
1180+
integrity sha512-cCQdw/Nfw8doXjN3onvUnWkuJjtVxx2iUjSOLMydvgI87YpW3x05uUXOVs4P+77YFVoFS6xbki+fmKK2JSCf8w==
1181+
dependencies:
1182+
"@babel/code-frame" "~7.10.4"
1183+
fs-extra "9.0.0"
1184+
json5 "^1.0.1"
1185+
write-file-atomic "^2.3.0"
1186+
11341187
11351188
version "0.0.11"
11361189
resolved "https://registry.yarnpkg.com/@expo/plist/-/plist-0.0.11.tgz#5d7900dc31df57d45a3524c061dde34aacc8dabf"
@@ -3196,12 +3249,13 @@ [email protected]:
31963249
resolved "https://registry.yarnpkg.com/expo-image-manipulator/-/expo-image-manipulator-9.0.0.tgz#0b6ad350b79e40a44164b6333e806a2ef6fc9708"
31973250
integrity sha512-hziIcUONz7JtsonEehuYvXk8xCSGDHR6A4ynZcUTbZQCzxWYu7Xq2wahREz/DBdu0vz0LBw38wFLuSpfgaFojQ==
31983251

3199-
expo-image-picker@9.2.0:
3200-
version "9.2.0"
3201-
resolved "https://registry.yarnpkg.com/expo-image-picker/-/expo-image-picker-9.2.0.tgz#e6cd4845c9e3d573d78cbdbdde9799a4c5c562f5"
3202-
integrity sha512-GC9rbbXg8fyuSvX8WFogGpJjrQ9lSdg17Lqimghm1o7fxjmObiRh7RMky4FB/KkoiRZAdwXN1/NDtjjTWCukSA==
3252+
expo-image-picker@10.0.0:
3253+
version "10.0.0"
3254+
resolved "https://registry.yarnpkg.com/expo-image-picker/-/expo-image-picker-10.0.0.tgz#24a3fd7335094191f148c3d2fbf9b496c500658f"
3255+
integrity sha512-smANMTtxqPDxGYPVQrppJAKxla2/UN4bTGfcmX7c8X8psaNUd4Bh8z9Uk/NUz00SGUWrU0Oa1K/rVrX1e0c2Hw==
32033256
dependencies:
3204-
expo-permissions "~10.0.0"
3257+
"@expo/config-plugins" "~1.0.13"
3258+
expo-permissions "~11.0.0"
32053259
uuid "7.0.2"
32063260

32073261
expo-keep-awake@~8.4.0:
@@ -3228,12 +3282,19 @@ expo-location@~10.0.0:
32283282
resolved "https://registry.yarnpkg.com/expo-location/-/expo-location-10.0.0.tgz#2923411649434f2f079343b163b13c5c9eee8b2d"
32293283
integrity sha512-QLEb0iaBv4/blLxxfKRj2/HPisY+1t+g6MgegqZ1j1U/0qih4dvzUQrxie9ZOZyQB9gnXFCRnZv3QzHEb52dcA==
32303284

3231-
3232-
version "10.0.0"
3233-
resolved "https://registry.yarnpkg.com/expo-media-library/-/expo-media-library-10.0.0.tgz#44ab985fa684a9cf5b23d50ac5874b61bfe779c7"
3234-
integrity sha512-/edgaLU8ClYEgwmiMknpNbkouTNZlL/FNAxcSpPlTmXuRAqd2YmE5BpNOe1demDrR1VWTrZ8/ekS/RwQAWQU2g==
3285+
3286+
version "11.0.0"
3287+
resolved "https://registry.yarnpkg.com/expo-media-library/-/expo-media-library-11.0.0.tgz#e37f1ff0c5a19c14a3989ad2b4f8b9f26522c23f"
3288+
integrity sha512-yRCce1tmn0WuVC64E+eS4Ez0w8jO4UVf0wz/rAYxJHquSOOC40HRQhzvmAhvAhfzeNGrVvQW/5j+IX+yzwq2QA==
3289+
dependencies:
3290+
"@expo/config-plugins" "~1.0.13"
3291+
3292+
[email protected], expo-permissions@~11.0.0:
3293+
version "11.0.0"
3294+
resolved "https://registry.yarnpkg.com/expo-permissions/-/expo-permissions-11.0.0.tgz#10889073121fea42bbfc35f09a35fa17a316b233"
3295+
integrity sha512-5+sFdU1HS/4aK9O7AsoLSNjG4f0UzlA3/nBHOPnWxxY2HRFnQp764tSsfSJRnGhM89Qxort6n2RzOusMoNP5ig==
32353296

3236-
expo-permissions@10.0.0, expo-permissions@~10.0.0:
3297+
expo-permissions@~10.0.0:
32373298
version "10.0.0"
32383299
resolved "https://registry.yarnpkg.com/expo-permissions/-/expo-permissions-10.0.0.tgz#5b31c54d561d00c7e46cd02321bc3704c51c584b"
32393300
integrity sha512-b6oitd4JmFdQ7DxczZ2WRS9aDyqgVM7lEhy3JyKZ2dbU19C6NyHyLCcwssZgfzOfGnp2owoaWn3KU4zdrF5MIA==
@@ -3670,7 +3731,7 @@ [email protected]:
36703731
resolved "https://registry.yarnpkg.com/getenv/-/getenv-0.7.0.tgz#39b91838707e2086fd1cf6ef8777d1c93e14649e"
36713732
integrity sha1-ObkYOHB+IIb9HPbvh3fRyT4UZJ4=
36723733

3673-
[email protected], glob@^7.1.2, glob@^7.1.3:
3734+
[email protected], glob@^7.1.2, glob@^7.1.3, glob@^7.1.6:
36743735
version "7.1.6"
36753736
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
36763737
integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==
@@ -6461,24 +6522,39 @@ stream-buffers@~2.2.0:
64616522
version "0.0.0"
64626523
uid ""
64636524

6464-
"stream-chat-react-native-core@link:../..":
6465-
version "0.0.0"
6466-
uid ""
6467-
6468-
6469-
version "3.0.0-beta.0"
6470-
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-3.0.0-beta.0.tgz#1ee82715c053a368abd0cdec5a7e49b6149cdde3"
6471-
integrity sha512-/HTp9x3LNG5/SAM9MmmQVnfUXBaxB0SaP6THy2nVza5aZ2NoLHaCb0i2MNOYz9MjkWLorLmRu4/Q4opcGnOZJw==
6525+
6526+
version "3.0.0"
6527+
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-3.0.0.tgz#63424f643070ba4743c9746224310641e278df16"
6528+
integrity sha512-2oLmMS8RsoHEl6P46PT4Cp0wp86nLwgpAi+8sMCGFlwuAi9fIZb9jyEIJwlJkiHCn6Vj452zaWKfFo1QZK+2ag==
6529+
dependencies:
6530+
"@babel/runtime" "7.12.13"
6531+
"@gorhom/bottom-sheet" "3.0.0-alpha.0"
6532+
anchorme "^1.1.2"
6533+
dayjs "1.10.4"
6534+
file-loader "6.2.0"
6535+
i18next "19.8.7"
6536+
lodash-es "4.17.20"
6537+
metro-react-native-babel-preset "0.65.0"
6538+
mime-types "2.1.28"
6539+
path "0.12.7"
6540+
react-art "^16.8.6"
6541+
react-native-markdown-package "1.8.1"
6542+
stream-chat "3.0.0"
6543+
6544+
6545+
version "3.0.0"
6546+
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-3.0.0.tgz#470a648b24d3d905ebc67b61805c1c95377dbc7e"
6547+
integrity sha512-DyTcGm7iBdAftEbCzxu3cT/iDEuUeLL0AosOTeLZU7MCVwSWdlAhyhKSNB06YC7v6FhAatWOn1kwdJJpkBTUVg==
64726548
dependencies:
6473-
"@babel/runtime" "^7.12.5"
6549+
"@babel/runtime" "^7.12.13"
64746550
"@types/jsonwebtoken" "^8.5.0"
64756551
"@types/ws" "^7.4.0"
64766552
axios "^0.21.1"
64776553
base64-js "^1.5.1"
64786554
form-data "^3.0.0"
64796555
isomorphic-ws "^4.0.1"
64806556
jsonwebtoken "^8.5.1"
6481-
ws "^7.4.2"
6557+
ws "^7.4.3"
64826558

64836559
strict-uri-encode@^2.0.0:
64846560
version "2.0.0"
@@ -7064,11 +7140,16 @@ ws@^1.1.0, ws@^1.1.5:
70647140
options ">=0.0.5"
70657141
ultron "1.0.x"
70667142

7067-
ws@^7, ws@^7.4.2:
7143+
ws@^7:
70687144
version "7.4.2"
70697145
resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.2.tgz#782100048e54eb36fe9843363ab1c68672b261dd"
70707146
integrity sha512-T4tewALS3+qsrpGI/8dqNMLIVdq/g/85U98HPMa6F0m6xTbvhXU6RCQLqPH3+SlomNV/LdY6RXEbBpMH6EOJnA==
70717147

7148+
ws@^7.4.3:
7149+
version "7.4.3"
7150+
resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.3.tgz#1f9643de34a543b8edb124bdcbc457ae55a6e5cd"
7151+
integrity sha512-hr6vCR76GsossIRsr8OLR9acVVm1jyfEWvhbNjtgPOrfvAlKzvyeg/P6r8RuDjRyrcQoPQT7K0DGEPc7Ae6jzA==
7152+
70727153
xcode@^2.0.0, xcode@^2.1.0:
70737154
version "2.1.0"
70747155
resolved "https://registry.yarnpkg.com/xcode/-/xcode-2.1.0.tgz#bab64a7e954bb50ca8d19da7e09531c65a43ecfe"

expo-package/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
"expo-file-system": "^9.3.0",
2121
"expo-haptics": "^8.4.0",
2222
"expo-image-manipulator": "^9.0.0",
23-
"expo-image-picker": "^9.2.0",
24-
"expo-media-library": "^10.0.0",
25-
"expo-permissions": "^10.0.0",
23+
"expo-image-picker": "^10.0.0",
24+
"expo-media-library": "^11.0.0",
25+
"expo-permissions": "^11.0.0",
2626
"expo-sharing": "^8.5.0"
2727
},
2828
"scripts": {

expo-package/src/index.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { FlatList, Platform } from 'react-native';
2+
import { FlatList } from 'react-native';
33
import NetInfo from '@react-native-community/netinfo';
44
import { BlurView as ExpoBlurView } from 'expo-blur';
55
import * as DocumentPicker from 'expo-document-picker';
@@ -35,15 +35,19 @@ registerNativeHandlers({
3535
}
3636
},
3737
FlatList,
38+
getLocalAssetUri: async (assetId) => {
39+
try {
40+
const { localUri } = await MediaLibrary.getAssetInfoAsync(assetId);
41+
return localUri;
42+
} catch {
43+
throw new Error('getLocalAssetUri Error');
44+
}
45+
},
3846
getPhotos: async ({ after, first }) => {
3947
try {
40-
if (Platform.OS === 'android') {
41-
const { status } = await Permissions.askAsync(
42-
Permissions.MEDIA_LIBRARY,
43-
);
44-
if (status !== 'granted') {
45-
throw new Error('getPhotos Error');
46-
}
48+
const { status } = await Permissions.askAsync(Permissions.MEDIA_LIBRARY);
49+
if (status !== 'granted') {
50+
throw new Error('getPhotos Error');
4751
}
4852
const results = await MediaLibrary.getAssetsAsync({
4953
after,
@@ -52,6 +56,7 @@ registerNativeHandlers({
5256
});
5357
const assets = results.assets.map((asset) => ({
5458
height: asset.height,
59+
id: asset.id,
5560
source: 'picker',
5661
uri: asset.uri,
5762
width: asset.width,
@@ -138,8 +143,16 @@ registerNativeHandlers({
138143
},
139144
takePhoto: async ({ compressImageQuality = 1 }) => {
140145
try {
141-
const { status } = ImagePicker.getCameraPermissionsAsync();
142-
if (status === 'granted') {
146+
const permissionCheck = await ImagePicker.getCameraPermissionsAsync();
147+
const permissionGranted =
148+
permissionCheck?.status === 'granted'
149+
? permissionCheck
150+
: await Permissions.askAsync(Permissions.CAMERA);
151+
152+
if (
153+
permissionGranted?.status === 'granted' ||
154+
permissionGranted?.granted === true
155+
) {
143156
const photo = await ImagePicker.launchCameraAsync({
144157
quality: Math.min(Math.max(0, compressImageQuality), 1),
145158
});

jest-setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ registerNativeHandlers({
2020
compressImage: () => null,
2121
deleteFile: () => null,
2222
FlatList: () => null,
23+
getLocalAssetUri: () => null,
2324
getPhotos: () => null,
2425
NetInfo: {
2526
addEventListener: () => {},

native-package/src/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ registerNativeHandlers({
4646
}
4747
},
4848
FlatList,
49+
getLocalAssetUri: async (remoteUri) => {
50+
try {
51+
const localUri = await CameraRoll.save(remoteUri);
52+
return localUri;
53+
} catch {
54+
throw new Error('getLocalAssetUri Error');
55+
}
56+
},
4957
getPhotos: async ({ after, first }) => {
5058
try {
5159
if (Platform.OS === 'android') {

0 commit comments

Comments
 (0)