我尝试使用OutputStream(url:payloadFileURL,append :)函数发送大型视频文件,但是我的代码状态为 500 。 (我精确地说,当我发送1gb,2gb时,它就像是一种魅力)
这是完整的代码:Send big files with OutputStream
private func buildPayloadFile(videoFileURL: URL, boundary: String, fileName: String, eventId: Int, contactId: Int, type: Int) throws -> URL {
let mimetype = "video/mp4"
let payloadFileURL = URL(fileURLWithPath: NSTemporaryDirectory())
.appendingPathComponent(UUID().uuidString)
guard let stream = OutputStream(url: payloadFileURL, append: false) else {
throw UploadError.unableToOpenPayload(payloadFileURL)
}
stream.open()
//define the data post parameter
stream.write("--\(boundary)\r\n")
stream.write("Content-Disposition:form-data; name=\"eventId\"\r\n\r\n")
stream.write("\(eventId)\r\n")
stream.write("--\(boundary)\r\n")
stream.write("Content-Disposition:form-data; name=\"contactId\"\r\n\r\n")
stream.write("\(contactId)\r\n")
stream.write("--\(boundary)\r\n")
stream.write("Content-Disposition:form-data; name=\"type\"\r\n\r\n")
stream.write("\(type)\r\n")
stream.write("--\(boundary)\r\n")
stream.write("Content-Disposition:form-data; name=\"file\"; filename=\"\(fileName)\"\r\n")
stream.write("Content-Type: \(mimetype)\r\n\r\n")
if stream.append(contentsOf: videoFileURL) < 0 {
throw UploadError.unableToOpenVideo(videoFileURL)
}
stream.write("\r\n")
stream.write("--\(boundary)--\r\n")
stream.close()
return payloadFileURL
}
有什么想法吗?
答案 0 :(得分:1)
错误500表示服务器端出现问题。可能有以下几个原因:
-服务器端配置
-服务器磁盘空间
-服务器实施问题
还请检查您的客户代码:
-内容类型
-哑剧
-设备上有足够的空间。由于文件很大,因此在“缓存”期间