| POST | /upload | Tải file |
|---|
import Foundation
import ServiceStack
/**
* Upload file
*/
public class FileUpload : FileUploadRequest, IPost
{
required public init(){ super.init() }
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
}
}
public class FileUploadRequest : Codable
{
//fileUpload:IHttpFile ignored. Swift doesn't support interface properties
public var accessType:AccessType
public var storageStatus:StorageStatus
required public init(){}
}
public protocol IHttpFile
{
var name:String { get set }
var fileName:String { get set }
var contentLength:Int { get set }
var contentType:String { get set }
var inputStream:Data { get set }
}
public enum AccessType : String, Codable
{
case Public
case Restricted
}
public enum StorageStatus : String, Codable
{
case Draft
case Permanent
case Archive
}
public protocol IResponseRequest
{
var code:Int { get set }
var message:String { get set }
}
To override the Content-type in your clients, use the HTTP Accept Header, append the .other suffix or ?format=other
The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.
POST /upload HTTP/1.1
Host: etc-api.vsmlab.vn
Accept: text/jsonl
Content-Type: text/jsonl
Content-Length: length
{"fileUpload":null,"accessType":"Public","storageStatus":"Draft"}
HTTP/1.1 200 OK
Content-Type: text/jsonl
Content-Length: length
{Unable to show example output for type 'IResponseRequest' using the custom 'other' filter}Cannot dynamically create an instance of type 'tvpl.api.ServiceModel.IResponseRequest'. Reason: Cannot create an instance of an interface.