[GH-ISSUE #541] Is there any way to get progress data during a multipart post? #355

Closed
opened 2026-03-03 16:48:01 +03:00 by kerem · 4 comments
Owner

Originally created by @MickeDG on GitHub (Aug 17, 2019).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/541

Description:

I'm successfully doing a multipart post of a video and would like to show a progress bar to the user...

OAuth Provider? (Twitter, Github, ..):

OAuth Version:

  • Version 1
  • Version 2

OS (Please fill the version) :

  • iOS :
  • OSX :
  • TVOS :
  • WatchOS :

Installation method:

  • Carthage
  • CocoaPods
  • Swift Package Manager
  • Manually

Library version:

  • head
  • v2.0.0
  • v1.4.1
  • v1.2.1
  • v1.2 (Swift 4.0)
  • v1.0.0
  • v0.6
  • other: (Please fill in the version you are using.)

Xcode version:

  • 11.x (Swift 5.1)

  • 10.x (Swift 5.0)

  • 10.x (Swift 4.1)

  • 9.3 (Swift 4.1)

  • 9.0 (Swift 4.0)

  • other: (Please fill in the version you are using.)

  • objective c

Originally created by @MickeDG on GitHub (Aug 17, 2019). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/541 ### Description: I'm successfully doing a multipart post of a video and would like to show a progress bar to the user... ### OAuth Provider? (Twitter, Github, ..): ### OAuth Version: - [x] Version 1 - [ ] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [x] CocoaPods - [ ] Swift Package Manager - [ ] Manually ### Library version: - [ ] head - [x] v2.0.0 - [ ] v1.4.1 - [ ] v1.2.1 - [ ] v1.2 (Swift 4.0) - [ ] v1.0.0 - [ ] v0.6 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [ ] 11.x (Swift 5.1) - [ ] 10.x (Swift 5.0) - [x] 10.x (Swift 4.1) - [ ] 9.3 (Swift 4.1) - [ ] 9.0 (Swift 4.0) - [ ] other: (Please fill in the version you are using.) - [ ] objective c
kerem closed this issue 2026-03-03 16:48:01 +03:00
Author
Owner

@phimage commented on GitHub (Aug 20, 2019):

here github.com/OAuthSwift/OAuthSwift@a471698f0b/Sources/OAuthSwiftClient.swift (L22)
there is an URLSessionFactory

inside you could put a delegate to associate with the URLSession
for instance one with
https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1408299-urlsession

<!-- gh-comment-id:522886496 --> @phimage commented on GitHub (Aug 20, 2019): here https://github.com/OAuthSwift/OAuthSwift/blob/a471698f0b200a9ffe5572662a7b7a411f2511fc/Sources/OAuthSwiftClient.swift#L22 there is an `URLSessionFactory` inside you could put a delegate to associate with the URLSession for instance one with https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1408299-urlsession
Author
Owner

@MickeDG commented on GitHub (Aug 20, 2019):

Thanks - I understand the main idea but not exactly how to implement it. Do I insert a function like this one:

urlSession(_:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:)

in the the URLSessionFactory struct?

How do I then call it my code?

<!-- gh-comment-id:522962837 --> @MickeDG commented on GitHub (Aug 20, 2019): Thanks - I understand the main idea but not exactly how to implement it. Do I insert a function like this one: urlSession(_:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:) in the the URLSessionFactory struct? How do I then call it my code?
Author
Owner

@phimage commented on GitHub (Aug 20, 2019):

You make your own class or struct, which implement the delegate
then do client.sessionFactory.delegate = <yourclassorstruct>

and I think you will receive some events in your method. I have not tested it but if I put correctly the delegate in apple sessions and I do not put my own delegate ...

<!-- gh-comment-id:523025340 --> @phimage commented on GitHub (Aug 20, 2019): You make your own class or struct, which implement the delegate then do `client.sessionFactory.delegate = <yourclassorstruct>` and I think you will receive some events in your method. I have not tested it but if I put correctly the delegate in apple sessions and I do not put my own delegate ...
Author
Owner

@MickeDG commented on GitHub (Aug 21, 2019):

Thank you - I got it working! It was enough with the existing UrlSession delegate in URLSessionFactory

In my class:

class OTIUpload : NSObject, URLSessionTaskDelegate {

override init() {
        super.init()
        appDelegate.oauthSwift.client.sessionFactory.delegate = self
    }

func urlSession(_ session: URLSession, task: URLSessionTask, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) {
        let uploadProgress:Float = Float(totalBytesSent) / Float(totalBytesExpectedToSend)
        print(uploadProgress)
    }
<!-- gh-comment-id:523347014 --> @MickeDG commented on GitHub (Aug 21, 2019): Thank you - I got it working! It was enough with the existing UrlSession delegate in URLSessionFactory In my class: ``` class OTIUpload : NSObject, URLSessionTaskDelegate { override init() { super.init() appDelegate.oauthSwift.client.sessionFactory.delegate = self } func urlSession(_ session: URLSession, task: URLSessionTask, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) { let uploadProgress:Float = Float(totalBytesSent) / Float(totalBytesExpectedToSend) print(uploadProgress) } ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#355
No description provided.