Giter Site home page Giter Site logo

manifold's Introduction

Manifold

Easily construct multipart http requests in swift.

Example Usage

import Manifold

let manifold = Manifold()

func uploadAnImageFile() {
  // Set the boundary that separates each part of the request
  manifold.boundary = UUID().uuidString

  // Start building a new part for the request
  let part = Part()

  // request parts can have their own headers
  part.header("Content-Disposition", "form-data; name=\"image\"; filename=\"the-image.jpg\"")
  part.header("Content-Type", "image/jpeg")

  // The 'body' of this part is the contents of an image file
  part.body(InputStream(fileAtPath: pathToAFile)

  // add the part to the manifold object
  // any number of parts can be added. For Example, you may want to add a
  // second part containing additional form data that will be handled by the server
  manifold.append(part)

  //  Manifold will notify its delegate when encoding completes
  manifold.delegate = self
  manifold.encode()
}

func manifold(_ manifold: Manifold, didFinishEncoding stream: InputStream) {
  // Manifold encodes all its parts into a single input stream that can be
  // attached to an HTTPURLRequest
  var request = URLRequest(url: fileUploadURL)
  request.httpBodyStream =  stream

  // ... continue sending the HTTP request
}

func manifold(_ manifold: Manifold, didFailWithError error: Error) {
  print("An error occurred while encoding the multipart request")
}

Installation

Carthage

Add this to your Cartfile

github "jacobsimeon/Manifold"

Then run carthage update

manifold's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.