Open
Description
Describe the bug
It seems to take up double the memory when use try clientRequest.content.encode(Encodable.self, as: .formData)
.
In addition,
when the request fails, the memory will not be released
normally (still taking up double the memory).
After the request is successful, the memory will be released normally.
import Vapor
struct SendFile {
private static func generateVideoFile(_ filePath: String) throws -> File {
let videoFileURL = URL(fileURLWithPath: filePath)
var videoData = try Data(contentsOf: videoFileURL)
return File(data: ByteBuffer(data: videoData), filename: (filePath as NSString).lastPathComponent)
}
struct SendFile: Codable {
let file: File
let userID: String
}
static func sendVideo(_ filePath: String, to userID: String, app: Application) async throws {
let file = try generateVideoFile(filePath)
let sendFile = SendFile(file: file, userID: userID)
let response = try await app.client.post("URI") { clientRequest in
try clientRequest.content.encode(sendFile, as: .formData)
}
// ...
}
}
Environment
- Vapor 4
- Ubuntu 20.04