Skip to content

Commit 174066e

Browse files
authored
Merge pull request #1 from apivideo/Fix/large-upload
Fix() file size detection & change filepath to url for inputstream
2 parents c7a9cbe + 39f8d37 commit 174066e

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# Changelog
22
All changes to this project will be documented in this file.
33

4+
## [0.0.3] - 2021-11-22
5+
- Fix large upload request time out
6+
- Fix callback on wrong token
7+

Example/Podfile.lock

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
PODS:
2-
- Nimble (9.0.1)
3-
- Quick (2.2.1)
4-
- VideoUploaderIos (0.1.0)
2+
- VideoUploaderIos (0.0.1)
53

64
DEPENDENCIES:
7-
- Nimble (~> 9.0.1)
8-
- Quick (~> 2.2.0)
95
- VideoUploaderIos (from `../`)
106

11-
SPEC REPOS:
12-
trunk:
13-
- Nimble
14-
- Quick
15-
167
EXTERNAL SOURCES:
178
VideoUploaderIos:
189
:path: "../"
1910

2011
SPEC CHECKSUMS:
21-
Nimble: 7bed62ffabd6dbfe05f5925cbc43722533248990
22-
Quick: f5754d69b7013f5864c29aab9ae6f0c79c5bc200
23-
VideoUploaderIos: 1d4030a68a67a5c629ef828bdc31ff1cca3f3864
12+
VideoUploaderIos: 86cd961775812209075c569ac9be9cac39eaf134
2413

25-
PODFILE CHECKSUM: 76527896bd7398adfe97a9831371340404fe8331
14+
PODFILE CHECKSUM: ac1f8a3fcdb1f6ef59acc6c0ee946d9f4c1c456d
2615

2716
COCOAPODS: 1.10.1

VideoUploaderIos.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'VideoUploaderIos'
11-
s.version = '0.0.2'
11+
s.version = '0.0.3'
1212
s.summary = 'A library to upload video files to api.video platform.'
1313

1414
# This description is used to generate tags and improve search results.

VideoUploaderIos/Classes/VideoUploader.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public class VideoUploader {
3333
}
3434

3535
private func upload(apiPath: String, bearerToken: String?, fileName: String, filePath: String, url: URL, completion: @escaping (Dictionary<String, AnyObject>?, ApiError?) -> ()) {
36-
let fileSize = self.getFileSize(path: filePath)
36+
let data = try? Data(contentsOf: url)
37+
let fileSize = data!.count
3738
if(fileSize <= chunkSize) {
3839
self.uploadWithoutChunk(apiPath: apiPath, bearerToken: bearerToken, fileName: fileName, filePath: filePath, url: url, completion: completion)
3940
} else {
@@ -85,6 +86,8 @@ public class VideoUploader {
8586
}
8687

8788
private func uploadByChunk(apiPath: String, bearerToken: String?, fileName: String, filePath: String, url: URL, completion: @escaping (Dictionary<String, AnyObject>?, ApiError?) -> ()) {
89+
90+
var hasError: Bool = false
8891

8992
let data = try? Data(contentsOf: url)
9093
let fileSize = data!.count
@@ -97,7 +100,7 @@ public class VideoUploader {
97100
let mimetype = mimeType(for: filePath)
98101

99102
for offset in stride(from: 0, through: fileSize, by: chunkSize){
100-
let fileStream = InputStream(fileAtPath: filePath)!
103+
let fileStream = InputStream(url: url)!
101104
var chunkEnd = offset + chunkSize
102105

103106
// if last chunk
@@ -131,13 +134,19 @@ public class VideoUploader {
131134
if(videoId == nil) {
132135
videoId = json?["videoId"] as? String
133136
}
134-
semaphore.signal()
137+
135138
}else{
136139
completion(nil, apiError)
140+
hasError = true
137141
}
142+
semaphore.signal()
143+
138144
}
139145
semaphore.wait()
140146
fileStream.close()
147+
if(hasError){
148+
return
149+
}
141150
}
142151
if(readBytes == fileSize){
143152
completion(video, nil)

0 commit comments

Comments
 (0)