Skip to content

Commit 1b6aaec

Browse files
committed
fix: file:/// url for compression
1 parent 66b7fe9 commit 1b6aaec

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

example/ios/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ PODS:
282282
- React-jsinspector (0.64.1)
283283
- react-native-background-upload (6.2.4):
284284
- React
285-
- react-native-compressor (0.2.0):
285+
- react-native-compressor (0.3.5):
286286
- NextLevelSessionExporter
287287
- React-Core
288288
- react-native-create-thumbnail (1.4.1):
@@ -458,7 +458,7 @@ DEPENDENCIES:
458458
- React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`)
459459
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
460460
- "RNCMaskedView (from `../node_modules/@react-native-community/masked-view`)"
461-
- RNFS (from `../../node_modules/react-native-fs`)
461+
- RNFS (from `../node_modules/react-native-fs`)
462462
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
463463
- RNReanimated (from `../node_modules/react-native-reanimated`)
464464
- RNScreens (from `../node_modules/react-native-screens`)
@@ -551,7 +551,7 @@ EXTERNAL SOURCES:
551551
RNCMaskedView:
552552
:path: "../node_modules/@react-native-community/masked-view"
553553
RNFS:
554-
:path: "../../node_modules/react-native-fs"
554+
:path: "../node_modules/react-native-fs"
555555
RNGestureHandler:
556556
:path: "../node_modules/react-native-gesture-handler"
557557
RNReanimated:
@@ -591,7 +591,7 @@ SPEC CHECKSUMS:
591591
React-jsiexecutor: 124e8f99992490d0d13e0649d950d3e1aae06fe9
592592
React-jsinspector: 500a59626037be5b3b3d89c5151bc3baa9abf1a9
593593
react-native-background-upload: b85fac36cfee561c8b3a282e5700e50dc98249c5
594-
react-native-compressor: 8ab48b7bc33b8a3c2b19b31681bd58e4ff359e27
594+
react-native-compressor: b812fc2ca45f218c8393a2e9eb7da23f03c1c340
595595
react-native-create-thumbnail: d31c84dd69fb4d60aec0ff2f49bc0de41ede7b2c
596596
react-native-document-picker: 1a7518132d4a06b67f459be9bb1464a567d2b3b4
597597
react-native-image-picker: 474cf2c33c2b6671da53d293a16c97995f0aec15

ios/Video/VideoCompressor.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,17 @@ class VideoCompressor: RCTEventEmitter, URLSessionTaskDelegate {
8282
reject("failed", "Compression Failed", error)
8383
})
8484
}
85-
86-
@objc(upload:withOptions:withResolver:withRejecter:)
87-
func upload(filePath: String, options: [String: Any], resolve:@escaping RCTPromiseResolveBlock, reject:@escaping RCTPromiseRejectBlock) -> Void {
85+
86+
func makeValidUri(filePath: String) -> String {
8887
let fileWithUrl = URL(fileURLWithPath: filePath)
8988
let absoluteUrl = fileWithUrl.deletingLastPathComponent()
9089
let fileUrl = "file://\(absoluteUrl.path)/\(fileWithUrl.lastPathComponent)"
90+
return fileUrl;
91+
}
92+
93+
@objc(upload:withOptions:withResolver:withRejecter:)
94+
func upload(filePath: String, options: [String: Any], resolve:@escaping RCTPromiseResolveBlock, reject:@escaping RCTPromiseRejectBlock) -> Void {
95+
let fileUrl = makeValidUri(filePath: filePath)
9196

9297
guard let uuid = options["uuid"] as? String else {
9398
let uploadError = UploadError(message: "UUID is missing")
@@ -174,9 +179,11 @@ class VideoCompressor: RCTEventEmitter, URLSessionTaskDelegate {
174179

175180

176181
func compressVideo(url: URL, bitRate: Float?, onProgress: @escaping (Float) -> Void, onCompletion: @escaping (URL) -> Void, onFailure: @escaping (Error) -> Void){
177-
let tmpURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
182+
var tmpURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
178183
.appendingPathComponent(ProcessInfo().globallyUniqueString)
179184
.appendingPathExtension("mp4")
185+
tmpURL = URL(string:makeValidUri(filePath: tmpURL.absoluteString))!
186+
180187
var _bitRate=bitRate;
181188
let asset = AVAsset(url: url)
182189
guard asset.tracks.count >= 1 else {

0 commit comments

Comments
 (0)