vapor

Uploading files using Vapor

牧云@^-^@ 提交于 2019-12-05 02:08:53
I've seen in documentation in Body section that there's a support for file uploading right now - or at least I understand it this way 😅 I have no strong foundation in backend development - especially if it comes to frameworks which are still eveloving so fast as Vapor do. I wonder if someone can provide some real life example of file uploading? I was hoping for a simple web page with possibility to upload a file to the backend and then store it for future usage. tanner0101 Vapor allows for file upload using the Multipart encoding. You can read more about HTTP upload here: How does HTTP file

Doing joins with Fluent in a Vapor application

≡放荡痞女 提交于 2019-12-04 15:39:24
I'm struggling to figure out how to join my two tables together using fluent. In essence I want to run this SQL command: SELECT p.name, o.amount, o.amount * p.amount total FROM "OrderPoints" o INNER JOIN "Points" p ON o.points_id = p.id WHERE order_id = 10831 I've got my two models setup like so: final class OrderPoint: Codable, PostgreSQLModel, Content, Migration { var id: Int? = nil var orderID: Order.ID var pointID: Point.ID var amount: Double = 0 var point: Parent<OrderPoint, Point> { return parent(\.pointID) } } final class Point: Codable, PostgreSQLModel, Content, Migration { var id: Int

Using vapor-fluent to upsert models

点点圈 提交于 2019-12-04 14:39:22
I am currently struggling with doing an upsert with vapor/fluent. I have a model something like this: struct DeviceToken: PostgreSQLModel { var id: Int? var token: String var updatedAt: Date = Date() init(id: Int? = nil, token: String, updatedAt: Date = Date()) { self.id = id self.token = token self.updatedAt = updatedAt } } struct Account: PostgreSQLModel { var id: Int? let username: String let service: String ... let deviceTokenId: DeviceToken.ID init(id: Int? = nil, service: String, username: String, ..., deviceTokenId: DeviceToken.ID) { self.id = id self.username = username .... self

Validate JWT token with RS256 or RS512 with Swift iOS

风流意气都作罢 提交于 2019-12-04 13:16:22
I am building an iOS application in Swift that needs to be able to validate a JWT token signature with a public key certificate using either RS256 or RS512. I've been trying to find libraries that support such functionalities but have had issues implementing the ones I have found. My question is therefore what the recommended way to implement such functionality for a Swift iOS app is? The ideal scenario is to be able to use one of the recognized frameworks on JWT.io. The only Swift library on JWT.io that supports RS256 or RS512 is the following library: https://github.com/vapor/jwt The

Vapor 3 Beta Example Endpoint Request

▼魔方 西西 提交于 2019-12-04 11:17:07
问题 I am trying to find a simple example of how inside a router a person would send a request to the vapor sample endpoint http://example.vapor.codes/json , receive a response and map it to a struct or class. I've seen examples elsewhere for Vapor 2 but they are no longer relevant with Vapor 3 and the current Vapor 3 beta documentation isn't clear. Something like... router.get("sample") { req in //1. create client //2. send get request to sample endpoint at http://example.vapor.codes/json //3.

Vapor upload multiple files at once

若如初见. 提交于 2019-12-04 07:35:17
I want to upload multiple images in one POST request. Currently, the part of my request related to the file upload is taking one file and looks like this: return try req.content.decode(File.self).flatMap(to: Image.self) { (file) in try file.data.write(to: URL(fileURLWithPath: DirectoryConfig.detect().workDir + localImageStorage + file.filename)) return try Image(userID: user.requireID(), url: imageStorage + file.filename, filename: file.filename).save(on: req) } This works just fine. Now, I tried to change .decode(File.self) to .decode([File].self) , and do a loop for all files. When trying to

Image Upload in Vapor 3 using PostgreSQL

我只是一个虾纸丫 提交于 2019-12-04 01:22:26
I'm following this guys Martin Lasek Tutorials and now i'm at "image upload". It seems that no one has the answer to the question "How do you upload images i Vapor 3" Db connection is ok, all the other values are saved. This is mye create method: func create(_ req: Request) throws -> Future<Response> { return try req.content.decode(Question.self).flatMap { question in return question.save(on: req).map { _ in return req.redirect(to: "/form") } } } and Model: final class Question: PostgreSQLModel { var id: Int? var questionText: String var answers: [String] var theme: String? var imageName:

Vapor doesn't work with xcode 9 and swift 4

匆匆过客 提交于 2019-12-03 22:23:03
When I try to compiled my newly created vapor project with Xcode 9 I get 189 compile errors. What's the trick to making this work? I installed vapor and the toolbox, and create via 'vapor new test --template=api' and then 'vapor xcode' to start it up. Check that everything is up to date. The following builds and runs for me at this time: Use latest vapor toolbox. Currently: vapor new test --template=api cd test swift package tools-version # 4.0.0 # use `swift package tools-version --set-current` if needed rm Package.resolved vapor update vapor --version # Vapor Toolbox: 3.1.2 # Vapor Framework

Vapor 3 Beta Example Endpoint Request

半城伤御伤魂 提交于 2019-12-03 15:08:12
I am trying to find a simple example of how inside a router a person would send a request to the vapor sample endpoint http://example.vapor.codes/json , receive a response and map it to a struct or class. I've seen examples elsewhere for Vapor 2 but they are no longer relevant with Vapor 3 and the current Vapor 3 beta documentation isn't clear. Something like... router.get("sample") { req in //1. create client //2. send get request to sample endpoint at http://example.vapor.codes/json //3. handle response and map to a struct or class } My goal is to go grab something off the endpoint, turn it

How do I read this Swift syntax? [duplicate]

五迷三道 提交于 2019-12-02 06:21:40
This question already has an answer here: Parameters after opening bracket 1 answer I am using Vapor and one of the first thing is to use get method which looks like following: drop.get("hello") { request in return "Hello, world!" } Now my understanding was that the closures are like variable of type functions. Correct? Here I see we call a method get on an instance of Droplet class called drop and pass in a string. What is with the closure being called/passed inside the get method body? How do I read this? This is called trailing closure syntax . If the last parameter of a function is a