A tiny library makes uploading and downloading easier

Overview

Platform Language License Issues

Features

  • uploading/downloading multiple files concurrently or sequentially
    • grouping tasks with awesome custom operators (||| and -->)
  • supports background uploading/downloading
  • supports progress tracking (single task and group of tasks)
  • enable to resume, pause, cancel, retry the task
  • header configurable
  • request parameters configurable

Quick example

let path = NSBundle.mainBundle().pathForResource("bigfile", ofType: "zip")
let fileUrl = NSURL(fileURLWithPath: path!)!

let task = UploadTask(url: "http://server.com", file: fileUrl)
	.progress { sent, total in
		let per = Double(sent) / Double(total)
		println("uploading: \(per)")
	}
	.completed { response, json, error in
		println("completed")
	}

 
 Transporter.add(task1 ||| task2 ||| task3)                     // concurrent tasks
            .progress { bytes, total in
                let per = Double(bytes) / Double(total)
                println("concurrent tasks: \(per)")
            }
            .completed { alltasks in
                println("task1, task2, task3: completed")
            }
            .add(task4 --> task5 --> task6)                       // sequential tasks 
            .progress { bytes, total in
                println("serial tasks")
            }
            .resume()

Usage

// downloading task

let task = DownloadTask(url: downloadUrl, destination: des)
	.progress { bytes, total in
		let per = Double(bytes) / Double(total)
		println("downloading: \(per)")
	}
	.completed { response, _, error in
		println("completed")
	}


// uploading task
// upload types: File, Data, Stream

let task = UploadTask(url: "http://server.com", data: uploadData)
	.progress { sent, total in
		let per = Double(sent) / Double(total)
		println("uploading: \(per)")
	}
	.completed { response, json, error in
		println("completed")
	}


// using  `|||`  operator to create a group of concurrent tasks

Transporter.add(task1 ||| task2 ||| task3)

// using  `-->`  operator to create a group of sequential tasks

Transporter.add(task1 --> task2 --> task3)


// task

task.headers = ["key": "value"]
task.params = ["key": "value"]
task.pause()
task.cancel()
task.retry

// background handling
// add the following method in the app delegate

func application(application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: () -> Void) {
	Transporter.handleEventsForBackgroundURLSection(identifier, completionHandler: completionHandler)
}


// Transporter configurations

Transporter.headers = [key: value]
Transporter.timeoutIntervalForRequest = 30.0
Transporter.timeoutIntervalForResource = 24 * 60 * 60.0
Transporter.HTTPMaximumconnectionsPerHost = 5
			

Installation

  • Installation with CocoaPods
pod 'TransporterSwift', '0.1.1'

Then run the following command:

pod install
  • Copying all the files into your project
  • Using submodule

Todo

  • retry, pause, cancel
  • validation

Requirements

  • iOS 8.0+
  • Xcode 6.1

License

Transporter is released under the MIT license. See LICENSE for details.

You might also like...
Plugin and runtime library for using protobuf with Swift

Swift Protobuf Welcome to Swift Protobuf! Apple's Swift programming language is a perfect complement to Google's Protocol Buffer ("protobuf") serializ

Swish is a networking library that is particularly meant for requesting and decoding JSON via Decodable
Swish is a networking library that is particularly meant for requesting and decoding JSON via Decodable

Swish Nothing but net(working). Swish is a networking library that is particularly meant for requesting and decoding JSON via Decodable. It is protoco

A lightweight but powerful network library with simplified and expressive syntax based on AFNetworking.
A lightweight but powerful network library with simplified and expressive syntax based on AFNetworking.

XMNetworking English Document XMNetworking 是一个轻量的、简单易用但功能强大的网络库,基于 AFNetworking 3.0+ 封装。 其中,XM 前缀是我们团队 Xcode-Men 的缩写。 简介 如上图所示,XMNetworking 采用中心化的设计思想

An iOS library to route API paths to objects on client side with request, mapping, routing and auth layers

WANetworkRouting Developed and Maintained by ipodishima Founder & CTO at Wasappli Inc. Sponsored by Wisembly A routing library to fetch objects from a

Lightweight REST library for iOS and watchOS. Available on cococapods
Lightweight REST library for iOS and watchOS. Available on cococapods

RMHttp RMHttp is a Lightweight REST library for iOS and watchOS. Features Chainable Request URL / JSON Parameter Encoding HTTP Methods GET/POST/DELETE

A networking library for iOS, macOS, watchOS and tvOS

Thunder Request Thunder Request is a Framework used to simplify making http and https web requests. Installation Setting up your app to use ThunderBas

A new, clean and lean network interface reachability library written in Swift.

Reachability A new, clean and lean network interface reachability library written in Swift. Remarks Network reachability changes can be monitored usin

Conforming WebSocket (RFC 6455) client library for iOS and Mac OSX
Conforming WebSocket (RFC 6455) client library for iOS and Mac OSX

SwiftWebSocket Conforming WebSocket (RFC 6455) client library for iOS and Mac OS

FreeRDP is a free remote desktop protocol library and clients

FreeRDP: A Remote Desktop Protocol Implementation FreeRDP is a free implementation of the Remote Desktop Protocol (RDP), released under the Apache lic

Comments
  • Platform minimum requirement documented as ios 7.0+, but required ios 8.0 from podspec file

    Platform minimum requirement documented as ios 7.0+, but required ios 8.0 from podspec file

    While into file TransporterSwift.podspec there's a deployment target valued to "8.0", on README.md is stated the library is compatible with ios 7.0+ I this you should update README.md file to match requirements stated within podspec.

    opened by matteogirardi 1
  • Add CocoaPods installation instructions to readme

    Add CocoaPods installation instructions to readme

    Note: This might not be exactly what you want, but I found Transporter on CocoaPods and figured someone else might want to know it's there without straying from the readme.

    opened by yurrriq 1
  • upload issue!! I want to send json data

    upload issue!! I want to send json data

    Thank you for your good code. I can work veryyyy useful for this good code I have one question. I try to use upload function. simultaniously I send json data body so, when I upload photos, I send json data to my server. what can I do??

    opened by yoonyoungji 0
  • Problem with downloaded files not created in your Example

    Problem with downloaded files not created in your Example

    After a successfull download, my files are not created in des directory, so i changed this :

    let documentsPath: AnyObject = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask,true)[0]
    let des =  NSURL(string: documentsPath.stringByAppendingString("/file.pdf"))!
    

    By this :

    let fileManager = NSFileManager.defaultManager()
    let documentsPath: NSURL = fileManager.URLsForDirectory(.DocumentDirectory,inDomains: .UserDomainMask)[0] as NSURL
    let des =  documentsPath.URLByAppendingPathComponent("/file.pdf")
    

    And everytings worked perfectly.

    opened by jchesne 1
Releases(0.1.1)
Owner
Le Van Nghia
Software Engineer. Lover of OSS. Creator of PipeCD, Promviz, LotusLoad, Hakuba, MaterialKit... 🐳
Le Van Nghia
A modern download manager based on NSURLSession to deal with asynchronous downloading, management and persistence of multiple files.

TWRDownloadManager TWRDownloadManager A modern download manager for iOS (Objective C) based on NSURLSession to deal with asynchronous downloading, man

Michelangelo Chasseur 407 Nov 19, 2022
Tiny http server engine written in Swift programming language.

What is Swifter? Tiny http server engine written in Swift programming language. Branches * stable - lands on CocoaPods and others. Supports the latest

null 3.6k Dec 31, 2022
Make it easier to observe network connectivity in SwiftUI.

ReachabilityX ReachabilityX is built using NWPathMonitor from Apple's Network framework to provide an easy way to observe the network changes for Swif

Dscyre Scotti 8 Feb 4, 2022
APIProvider - API Provider Package for easier API management inspired by abstraction

APIProvider Using APIProvider you can easily communicate with all API endpoints

null 1 Apr 21, 2022
🌐 Makes Internet connectivity detection more robust by detecting Wi-Fi networks without Internet access.

Connectivity is a wrapper for Apple's Reachability providing a reliable measure of whether Internet connectivity is available where Reachability alone

Ross Butler 1.6k Dec 30, 2022
SwiftCANLib is a library used to process Controller Area Network (CAN) frames utilizing the Linux kernel open source library SOCKETCAN.

SwiftCANLib SwiftCANLib is a library used to process Controller Area Network (CAN) frames utilizing the Linux kernel open source library SOCKETCAN. Th

Tim Wise 4 Oct 25, 2021
QwikHttp is a robust, yet lightweight and simple to use HTTP networking library for iOS, tvOS and watchOS

QwikHttp is a robust, yet lightweight and simple to use HTTP networking library. It allows you to customize every aspect of your http requests within a single line of code, using a Builder style syntax to keep your code super clean.

Logan Sease 2 Mar 20, 2022
Lightweight library for web server applications in Swift on macOS and Linux powered by coroutines.

Why Zewo? • Support • Community • Contributing Zewo Zewo is a lightweight library for web applications in Swift. What sets Zewo apart? Zewo is not a w

Zewo 1.9k Dec 22, 2022
Lightweight REST and JSON library for Swift.

RestEssentials is an extremely lightweight REST and JSON library for Swift and can be used on iOS, iPadOS, macOS, tvOS, and watchOS. Features Easily p

null 37 Nov 2, 2022
Asynchronous socket networking library for Mac and iOS

CocoaAsyncSocket CocoaAsyncSocket provides easy-to-use and powerful asynchronous socket libraries for macOS, iOS, and tvOS. The classes are described

Robbie Hanson 12.3k Jan 8, 2023