48 lines
1.1 KiB
Swift
48 lines
1.1 KiB
Swift
|
//
|
||
|
// UploadFileEndpoint.swift
|
||
|
// APIService
|
||
|
//
|
||
|
// Created by Javier Cicchelli on 04/12/2022.
|
||
|
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import Foundation
|
||
|
|
||
|
struct UploadFileEndpoint: Endpoint {
|
||
|
let path: String
|
||
|
let method: RequestMethod
|
||
|
let credentials: BasicCredentials
|
||
|
let headers: [String : String]
|
||
|
let body: Data?
|
||
|
}
|
||
|
|
||
|
// MARK: - Initialisers
|
||
|
|
||
|
extension UploadFileEndpoint {
|
||
|
init(
|
||
|
itemId: String,
|
||
|
fileName: String,
|
||
|
fileData: Data,
|
||
|
username: String,
|
||
|
password: String
|
||
|
) {
|
||
|
self.path = .init(format: .Formats.itemsWithId, itemId)
|
||
|
self.method = .post
|
||
|
self.credentials = .init(
|
||
|
username: username,
|
||
|
password: password
|
||
|
)
|
||
|
self.headers = [
|
||
|
.Header.Keys.contentType: .Header.Values.contentTypeOctet,
|
||
|
.Header.Keys.contentDisposition: .init(format: .Formats.attachment, fileName)
|
||
|
]
|
||
|
self.body = fileData
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// MARK: - String+Formats
|
||
|
|
||
|
private extension String.Formats {
|
||
|
static let attachment = "attachment;filename*=utf-8''%@"
|
||
|
}
|