Skip to content

Commit 4db992c

Browse files
author
Tigran Hambardzumyan
authored
feat(#183): Upload extensions
* Adding some extensions for upload * Fix alignment warnings
1 parent 3288e28 commit 4db992c

File tree

1 file changed

+312
-0
lines changed

1 file changed

+312
-0
lines changed

Sources/RxAlamofire/RxAlamofire.swift

Lines changed: 312 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,40 @@ public func upload(_ file: URL,
362362
return Alamofire.Session.default.rx.upload(file, urlRequest: urlRequest, interceptor: interceptor)
363363
}
364364

365+
/**
366+
Returns an observable of a request using the shared manager instance to upload a specific file to a specified URL.
367+
The request is started immediately.
368+
369+
- parameter file: An instance of `URL` holding the information of the local file.
370+
- parameter url: An object adopting `URLConvertible`
371+
- parameter method: Alamofire method object
372+
- parameter headers: A `HTTPHeaders` containing all the additional headers
373+
- returns: The observable of `UploadRequest` for the created request.
374+
*/
375+
public func upload(_ file: URL,
376+
to url: URLConvertible,
377+
method: HTTPMethod,
378+
headers: HTTPHeaders? = nil) -> Observable<UploadRequest> {
379+
return Alamofire.Session.default.rx.upload(file, to: url, method: method, headers: headers)
380+
}
381+
382+
/**
383+
Returns an observable of a request progress using the shared manager instance to upload a specific file to a specified URL.
384+
The request is started immediately.
385+
386+
- parameter file: An instance of `URL` holding the information of the local file.
387+
- parameter url: An object adopting `URLConvertible`
388+
- parameter method: Alamofire method object
389+
- parameter headers: A `HTTPHeaders` containing all the additional headers
390+
- returns: The observable of `RxProgress` for the created request.
391+
*/
392+
public func upload(_ file: URL,
393+
to url: URLConvertible,
394+
method: HTTPMethod,
395+
headers: HTTPHeaders? = nil) -> Observable<RxProgress> {
396+
return Alamofire.Session.default.rx.upload(file, to: url, method: method, headers: headers)
397+
}
398+
365399
/**
366400
Returns an observable of a request using the shared manager instance to upload any data to a specified URL.
367401
The request is started immediately.
@@ -377,6 +411,40 @@ public func upload(_ data: Data,
377411
return Alamofire.Session.default.rx.upload(data, urlRequest: urlRequest, interceptor: interceptor)
378412
}
379413

414+
/**
415+
Returns an observable of a request using the shared manager instance to upload a specific file to a specified URL.
416+
The request is started immediately.
417+
418+
- parameter data: An instance of `Data` holding the information of the local file.
419+
- parameter url: An object adopting `URLConvertible`
420+
- parameter method: Alamofire method object
421+
- parameter headers: A `HTTPHeaders` containing all the additional headers
422+
- returns: The observable of `UploadRequest` for the created request.
423+
*/
424+
public func upload(_ data: Data,
425+
to url: URLConvertible,
426+
method: HTTPMethod,
427+
headers: HTTPHeaders? = nil) -> Observable<UploadRequest> {
428+
return Alamofire.Session.default.rx.upload(data, to: url, method: method, headers: headers)
429+
}
430+
431+
/**
432+
Returns an observable of a request progress using the shared manager instance to upload a specific file to a specified URL.
433+
The request is started immediately.
434+
435+
- parameter data: An instance of `Data` holding the information of the local file.
436+
- parameter url: An object adopting `URLConvertible`
437+
- parameter method: Alamofire method object
438+
- parameter headers: A `HTTPHeaders` containing all the additional headers
439+
- returns: The observable of `RxProgress` for the created request.
440+
*/
441+
public func upload(_ data: Data,
442+
to url: URLConvertible,
443+
method: HTTPMethod,
444+
headers: HTTPHeaders? = nil) -> Observable<RxProgress> {
445+
return Alamofire.Session.default.rx.upload(data, to: url, method: method, headers: headers)
446+
}
447+
380448
/**
381449
Returns an observable of a request using the shared manager instance to upload any stream to a specified URL.
382450
The request is started immediately.
@@ -392,6 +460,87 @@ public func upload(_ stream: InputStream,
392460
return Alamofire.Session.default.rx.upload(stream, urlRequest: urlRequest, interceptor: interceptor)
393461
}
394462

463+
/**
464+
Returns an observable of a request using the shared manager instance to upload a specific file to a specified URL.
465+
The request is started immediately.
466+
467+
- parameter stream: The `InputStream` to upload.
468+
- parameter url: An object adopting `URLConvertible`
469+
- parameter method: Alamofire method object
470+
- parameter headers: A `HTTPHeaders` containing all the additional headers
471+
- returns: The observable of `UploadRequest` for the created request.
472+
*/
473+
public func upload(_ stream: InputStream,
474+
to url: URLConvertible,
475+
method: HTTPMethod,
476+
headers: HTTPHeaders? = nil) -> Observable<UploadRequest> {
477+
return Alamofire.Session.default.rx.upload(stream, to: url, method: method, headers: headers)
478+
}
479+
480+
/**
481+
Returns an observable of a request progress using the shared manager instance to upload a specific file to a specified URL.
482+
The request is started immediately.
483+
484+
- parameter stream: The `InputStream` to upload.
485+
- parameter url: An object adopting `URLConvertible`
486+
- parameter method: Alamofire method object
487+
- parameter headers: A `HTTPHeaders` containing all the additional headers
488+
- returns: The observable of `RxProgress` for the created request.
489+
*/
490+
public func upload(_ stream: InputStream,
491+
to url: URLConvertible,
492+
method: HTTPMethod,
493+
headers: HTTPHeaders? = nil) -> Observable<RxProgress> {
494+
return Alamofire.Session.default.rx.upload(stream, to: url, method: method, headers: headers)
495+
}
496+
497+
/**
498+
Returns an observable of a request using the shared manager instance to upload any stream to a specified URL.
499+
The request is started immediately.
500+
501+
- parameter multipartFormData: The block for building `MultipartFormData`.
502+
- parameter urlRequest: The request object to start the upload.
503+
- returns: The observable of `UploadRequest` for the created upload request.
504+
*/
505+
public func upload(multipartFormData: @escaping (MultipartFormData) -> Void,
506+
urlRequest: URLRequestConvertible) -> Observable<UploadRequest> {
507+
return Alamofire.Session.default.rx.upload(multipartFormData: multipartFormData, urlRequest: urlRequest)
508+
}
509+
510+
/**
511+
Returns an observable of a request using the shared manager instance to upload a specific file to a specified URL.
512+
The request is started immediately.
513+
514+
- parameter multipartFormData: The block for building `MultipartFormData`.
515+
- parameter url: An object adopting `URLConvertible`
516+
- parameter method: Alamofire method object
517+
- parameter headers: A `HTTPHeaders` containing all the additional headers
518+
- returns: The observable of `UploadRequest` for the created request.
519+
*/
520+
public func upload(multipartFormData: @escaping (MultipartFormData) -> Void,
521+
to url: URLConvertible,
522+
method: HTTPMethod,
523+
headers: HTTPHeaders? = nil) -> Observable<UploadRequest> {
524+
return Alamofire.Session.default.rx.upload(multipartFormData: multipartFormData, to: url, method: method, headers: headers)
525+
}
526+
527+
/**
528+
Returns an observable of a request progress using the shared manager instance to upload a specific file to a specified URL.
529+
The request is started immediately.
530+
531+
- parameter multipartFormData: The block for building `MultipartFormData`.
532+
- parameter url: An object adopting `URLConvertible`
533+
- parameter method: Alamofire method object
534+
- parameter headers: A `HTTPHeaders` containing all the additional headers
535+
- returns: The observable of `RxProgress` for the created request.
536+
*/
537+
public func upload(multipartFormData: @escaping (MultipartFormData) -> Void,
538+
to url: URLConvertible,
539+
method: HTTPMethod,
540+
headers: HTTPHeaders? = nil) -> Observable<RxProgress> {
541+
return Alamofire.Session.default.rx.upload(multipartFormData: multipartFormData, to: url, method: method, headers: headers)
542+
}
543+
395544
// MARK: Download
396545

397546
/**
@@ -789,6 +938,43 @@ extension Reactive where Base: Alamofire.Session {
789938
}
790939
}
791940

941+
/**
942+
Returns an observable of a request using the shared manager instance to upload a specific file to a specified URL.
943+
The request is started immediately.
944+
945+
- parameter file: An instance of `URL` holding the information of the local file.
946+
- parameter url: An object adopting `URLConvertible`
947+
- parameter method: Alamofire method object
948+
- parameter headers: A `HTTPHeaders` containing all the additional headers
949+
- returns: The observable of `UploadRequest` for the created request.
950+
*/
951+
public func upload(_ file: URL,
952+
to url: URLConvertible,
953+
method: HTTPMethod,
954+
headers: HTTPHeaders? = nil) -> Observable<UploadRequest> {
955+
return request { manager in
956+
manager.upload(file, to: url, method: method, headers: headers)
957+
}
958+
}
959+
960+
/**
961+
Returns an observable of a request progress using the shared manager instance to upload a specific file to a specified URL.
962+
The request is started immediately.
963+
964+
- parameter file: An instance of `URL` holding the information of the local file.
965+
- parameter url: An object adopting `URLConvertible`
966+
- parameter method: Alamofire method object
967+
- parameter headers: A `HTTPHeaders` containing all the additional headers
968+
- returns: The observable of `RxProgress` for the created request.
969+
*/
970+
public func upload(_ file: URL,
971+
to url: URLConvertible,
972+
method: HTTPMethod,
973+
headers: HTTPHeaders? = nil) -> Observable<RxProgress> {
974+
return upload(file, to: url, method: method, headers: headers)
975+
.flatMap { $0.rx.progress() }
976+
}
977+
792978
/**
793979
Returns an observable of a request using the shared manager instance to upload any data to a specified URL.
794980
The request is started immediately.
@@ -806,6 +992,43 @@ extension Reactive where Base: Alamofire.Session {
806992
}
807993
}
808994

995+
/**
996+
Returns an observable of a request using the shared manager instance to upload a specific file to a specified URL.
997+
The request is started immediately.
998+
999+
- parameter data: An instance of `Data` holding the information of the local file.
1000+
- parameter url: An object adopting `URLConvertible`
1001+
- parameter method: Alamofire method object
1002+
- parameter headers: A `HTTPHeaders` containing all the additional headers
1003+
- returns: The observable of `UploadRequest` for the created request.
1004+
*/
1005+
public func upload(_ data: Data,
1006+
to url: URLConvertible,
1007+
method: HTTPMethod,
1008+
headers: HTTPHeaders? = nil) -> Observable<UploadRequest> {
1009+
return request { manager in
1010+
manager.upload(data, to: url, method: method, headers: headers)
1011+
}
1012+
}
1013+
1014+
/**
1015+
Returns an observable of a request progress using the shared manager instance to upload a specific file to a specified URL.
1016+
The request is started immediately.
1017+
1018+
- parameter data: An instance of `Data` holding the information of the local file.
1019+
- parameter url: An object adopting `URLConvertible`
1020+
- parameter method: Alamofire method object
1021+
- parameter headers: A `HTTPHeaders` containing all the additional headers
1022+
- returns: The observable of `RxProgress` for the created request.
1023+
*/
1024+
public func upload(_ data: Data,
1025+
to url: URLConvertible,
1026+
method: HTTPMethod,
1027+
headers: HTTPHeaders? = nil) -> Observable<RxProgress> {
1028+
return upload(data, to: url, method: method, headers: headers)
1029+
.flatMap { $0.rx.progress() }
1030+
}
1031+
8091032
/**
8101033
Returns an observable of a request using the shared manager instance to upload any stream to a specified URL.
8111034
The request is started immediately.
@@ -823,6 +1046,95 @@ extension Reactive where Base: Alamofire.Session {
8231046
}
8241047
}
8251048

1049+
/**
1050+
Returns an observable of a request using the shared manager instance to upload a specific file to a specified URL.
1051+
The request is started immediately.
1052+
1053+
- parameter stream: The `InputStream` to upload.
1054+
- parameter url: An object adopting `URLConvertible`
1055+
- parameter method: Alamofire method object
1056+
- parameter headers: A `HTTPHeaders` containing all the additional headers
1057+
- returns: The observable of `UploadRequest` for the created request.
1058+
*/
1059+
public func upload(_ stream: InputStream,
1060+
to url: URLConvertible,
1061+
method: HTTPMethod,
1062+
headers: HTTPHeaders? = nil) -> Observable<UploadRequest> {
1063+
return request { manager in
1064+
manager.upload(stream, to: url, method: method, headers: headers)
1065+
}
1066+
}
1067+
1068+
/**
1069+
Returns an observable of a request progress using the shared manager instance to upload a specific file to a specified URL.
1070+
The request is started immediately.
1071+
1072+
- parameter stream: The `InputStream` to upload.
1073+
- parameter url: An object adopting `URLConvertible`
1074+
- parameter method: Alamofire method object
1075+
- parameter headers: A `HTTPHeaders` containing all the additional headers
1076+
- returns: The observable of `RxProgress` for the created request.
1077+
*/
1078+
public func upload(_ stream: InputStream,
1079+
to url: URLConvertible,
1080+
method: HTTPMethod,
1081+
headers: HTTPHeaders? = nil) -> Observable<RxProgress> {
1082+
return upload(stream, to: url, method: method, headers: headers)
1083+
.flatMap { $0.rx.progress() }
1084+
}
1085+
1086+
/**
1087+
Returns an observable of a request using the shared manager instance to upload any stream to a specified URL.
1088+
The request is started immediately.
1089+
1090+
- parameter multipartFormData: The block for building `MultipartFormData`.
1091+
- parameter urlRequest: The request object to start the upload.
1092+
- returns: The observable of `UploadRequest` for the created upload request.
1093+
*/
1094+
public func upload(multipartFormData: @escaping (MultipartFormData) -> Void,
1095+
urlRequest: URLRequestConvertible) -> Observable<UploadRequest> {
1096+
return request { manager in
1097+
manager.upload(multipartFormData: multipartFormData, with: urlRequest)
1098+
}
1099+
}
1100+
1101+
/**
1102+
Returns an observable of a request using the shared manager instance to upload a specific file to a specified URL.
1103+
The request is started immediately.
1104+
1105+
- parameter multipartFormData: The block for building `MultipartFormData`.
1106+
- parameter url: An object adopting `URLConvertible`
1107+
- parameter method: Alamofire method object
1108+
- parameter headers: A `HTTPHeaders` containing all the additional headers
1109+
- returns: The observable of `UploadRequest` for the created request.
1110+
*/
1111+
public func upload(multipartFormData: @escaping (MultipartFormData) -> Void,
1112+
to url: URLConvertible,
1113+
method: HTTPMethod,
1114+
headers: HTTPHeaders? = nil) -> Observable<UploadRequest> {
1115+
return request { manager in
1116+
manager.upload(multipartFormData: multipartFormData, to: url, method: method, headers: headers)
1117+
}
1118+
}
1119+
1120+
/**
1121+
Returns an observable of a request progress using the shared manager instance to upload a specific file to a specified URL.
1122+
The request is started immediately.
1123+
1124+
- parameter multipartFormData: The block for building `MultipartFormData`.
1125+
- parameter url: An object adopting `URLConvertible`
1126+
- parameter method: Alamofire method object
1127+
- parameter headers: A `HTTPHeaders` containing all the additional headers
1128+
- returns: The observable of `RxProgress` for the created request.
1129+
*/
1130+
public func upload(multipartFormData: @escaping (MultipartFormData) -> Void,
1131+
to url: URLConvertible,
1132+
method: HTTPMethod,
1133+
headers: HTTPHeaders? = nil) -> Observable<RxProgress> {
1134+
return upload(multipartFormData: multipartFormData, to: url, method: method, headers: headers)
1135+
.flatMap { $0.rx.progress() }
1136+
}
1137+
8261138
// MARK: Download
8271139

8281140
/**

0 commit comments

Comments
 (0)