tvpl.api

<back to all web services

FileUpload

Upload file

Requires Authentication
The following routes are available for this service:
POST/uploadTả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 }

}


Swift FileUpload DTOs

To override the Content-type in your clients, use the HTTP Accept Header, append the .csv suffix or ?format=csv

HTTP + CSV

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/csv
Content-Type: text/csv
Content-Length: length

{"fileUpload":null,"accessType":"Public","storageStatus":"Draft"}
HTTP/1.1 200 OK
Content-Type: text/csv
Content-Length: length

{Unable to show example output for type 'IResponseRequest' using the custom 'csv' filter}Cannot dynamically create an instance of type 'tvpl.api.ServiceModel.IResponseRequest'. Reason: Cannot create an instance of an interface.