All Projects → mcritz → Vaporuploads

mcritz / Vaporuploads

Demonstrating uploads in Vapor 4. Particularly large streaming uploads.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Vaporuploads

Swiftserverside Vapor
🦄 Swift server open source projects based on the Swift 4.1 and Vapor 3 frameworks. (Swift 服务端开源项目)
Stars: ✭ 588 (+2994.74%)
Mutual labels:  server-side-swift, vapor
Jwt
Vapor JWT provider
Stars: ✭ 266 (+1300%)
Mutual labels:  server-side-swift, vapor
awesome-vapor
A curated list of Vapor-related awesome projects.
Stars: ✭ 907 (+4673.68%)
Mutual labels:  vapor, server-side-swift
sourcery-templates
Building Vapor projects using meta programming with Sourcery ✨
Stars: ✭ 24 (+26.32%)
Mutual labels:  vapor, server-side-swift
Vapor
💧 A server-side Swift HTTP web framework.
Stars: ✭ 21,194 (+111447.37%)
Mutual labels:  server-side-swift, vapor
template
A Vapor template for convenient and fast scaffolding 🏎
Stars: ✭ 33 (+73.68%)
Mutual labels:  vapor, server-side-swift
Vaporschool
Learn how to build vapor applications from rookie to champion in a constructive way!
Stars: ✭ 259 (+1263.16%)
Mutual labels:  server-side-swift, vapor
flash
Flash messages between views ⚡️
Stars: ✭ 34 (+78.95%)
Mutual labels:  vapor, server-side-swift
Redis
Vapor provider for RediStack
Stars: ✭ 434 (+2184.21%)
Mutual labels:  server-side-swift, vapor
Steampress
A Blogging Engine and Platform written in Swift for use with the Vapor Framework
Stars: ✭ 337 (+1673.68%)
Mutual labels:  server-side-swift, vapor
SwiftString
A comprehensive, lightweight string extension for Swift 3.x & 4.0
Stars: ✭ 117 (+515.79%)
Mutual labels:  vapor, server-side-swift
Swiftybeaver
Convenient & secure logging during development & release in Swift 3, 4 & 5
Stars: ✭ 5,392 (+28278.95%)
Mutual labels:  server-side-swift, vapor
Stevenson
Stevenson is a Vapor framework designed to build integrations between Slack apps, GitHub, JIRA and CI services (CircleCI).
Stars: ✭ 57 (+200%)
Mutual labels:  vapor, server-side-swift
Stacked
Stack traces for Swift on Mac and Linux 📚
Stars: ✭ 24 (+26.32%)
Mutual labels:  server-side-swift, vapor
bugsnag
Report errors with Bugsnag 🐛
Stars: ✭ 37 (+94.74%)
Mutual labels:  vapor, server-side-swift
postgres-kit
🐘 Non-blocking, event-driven Swift client for PostgreSQL.
Stars: ✭ 125 (+557.89%)
Mutual labels:  vapor, server-side-swift
routing-kit
🚍 High-performance trie-node router.
Stars: ✭ 95 (+400%)
Mutual labels:  vapor, server-side-swift
gatekeeper
Rate limiting middleware for Vapor 👮
Stars: ✭ 54 (+184.21%)
Mutual labels:  vapor, server-side-swift
Leaf
🍃 An expressive, performant, and extensible templating language built for Swift.
Stars: ✭ 310 (+1531.58%)
Mutual labels:  server-side-swift, vapor
Sockets
🔌 Non-blocking TCP socket layer, with event-driven server and client.
Stars: ✭ 559 (+2842.11%)
Mutual labels:  server-side-swift, vapor

VaporUploads

Demonstrating File Uploads in Vapor 4

Basics

Files get sent over the internet in different ways. Vapor supports three that I’m aware of. Collecting data in the request, streaming data in a request, and streaming data in WebSockets.

Vapor provides a handy File type that can be used in your model to encode useful information like file name.

Collect

You can upload files on a POST and collect all the incoming bytes with body: .collect(maxSize) as seen in routes.swift:11.

This is straightforward. Increase the maxSize value and you’ll use that much more system RAM per active request. The body will collect common inbound encodings including JSON and form/multipart.

The obvious downside is that if you’re expecting many requests or large uploads your memory footprint will balloon. Imagine uploading a multigigabyte file into RAM!

HTTP Streaming

You can also upload files on a POST and stream the incoming bytes for handling as seen in routes.swift:18 and StreamController.swift:24

This is a bit trickier. You’ll need to understand:

  • Promises
  • Futures
  • NIO’s file handling types: NonBlockingFileIO and NIOFileHandle

These aren’t extremely difficult concepts, but if its new domain expertise for you then you’ll have the personal benefit of learning something new.

The technical benefit is that the inbound bytes are handled and released from memory, keeping memory usage extremely low: KB instead of MB/GB. You can support many concurrent connections. You can stream very large files.

WebSocket Streaming

Not yet in this repository, but worth noting for its novelty and performance potential is that you can stream binary data over WebSockets. The strategy is fairly similar to HTTP Streaming because you’ll read inbound bytes (websocket.onBinary()) and handle them with Promise and Future types, but the implementation relies on the WebSocket API.

So, you need to set up the websocket connection, handle inbound bytes, communicate outcomes to the client, and close the connection when appropriate. If you want, I can provide a proof of concept example. Let me know on twitter: @mike_critz

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].