Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Commit 0c690b0

Browse files
committed
Added better url parsing logic for remote image extension extraction. Also added BMP support since react native <Image> supports BMP.
1 parent 7e5c7eb commit 0c690b0

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

lib/FileSystem.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Platform } from 'react-native';
1111
import pathLib from 'path';
1212
import RNFetchBlob from 'react-native-fetch-blob';
1313
import sha1 from 'crypto-js/sha1';
14+
import URL from 'url-parse';
1415

1516
export class FileSystem {
1617

@@ -138,7 +139,8 @@ export class FileSystem {
138139
*/
139140
getFileNameFromUrl(url) {
140141

141-
let urlExt = url.split('.').pop();
142+
const urlParts = new URL(url);
143+
const urlExt = urlParts.pathname.split('.').pop();
142144

143145
let extension = null;
144146
switch(urlExt) {
@@ -156,6 +158,10 @@ export class FileSystem {
156158
case 'JPEG':
157159
extension = 'jpg';
158160
break;
161+
case 'BMP':
162+
case 'bmp':
163+
extension = 'bmp';
164+
break;
159165
default:
160166
throw new Error('url has invalid file extension.');
161167
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"react-native-fetch-blob": "0.10.8",
6060
"react-native-uuid": "^1.4.9",
6161
"traverse": "^0.6.6",
62+
"url-parse": "^1.2.0",
6263
"validator": "^9.0.0"
6364
}
6465
}

yarn.lock

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3696,6 +3696,10 @@ qs@~6.5.1:
36963696
version "6.5.1"
36973697
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8"
36983698

3699+
querystringify@~1.0.0:
3700+
version "1.0.0"
3701+
resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-1.0.0.tgz#6286242112c5b712fa654e526652bf6a13ff05cb"
3702+
36993703
random-bytes@~1.0.0:
37003704
version "1.0.0"
37013705
resolved "https://registry.yarnpkg.com/random-bytes/-/random-bytes-1.0.0.tgz#4f68a1dc0ae58bd3fb95848c30324db75d64360b"
@@ -4039,6 +4043,10 @@ require-uncached@^1.0.3:
40394043
caller-path "^0.1.0"
40404044
resolve-from "^1.0.0"
40414045

4046+
requires-port@~1.0.0:
4047+
version "1.0.0"
4048+
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
4049+
40424050
resolve-from@^1.0.0:
40434051
version "1.0.1"
40444052
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226"
@@ -4675,6 +4683,13 @@ [email protected], unpipe@~1.0.0:
46754683
version "1.0.0"
46764684
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
46774685

4686+
url-parse@^1.2.0:
4687+
version "1.2.0"
4688+
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.2.0.tgz#3a19e8aaa6d023ddd27dcc44cb4fc8f7fec23986"
4689+
dependencies:
4690+
querystringify "~1.0.0"
4691+
requires-port "~1.0.0"
4692+
46784693
[email protected], util-deprecate@~1.0.1:
46794694
version "1.0.2"
46804695
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"

0 commit comments

Comments
 (0)