Skip to content
This repository has been archived by the owner on Jan 28, 2019. It is now read-only.

Commit

Permalink
Merge pull request #4 from kapilkm9/bug/upload_file_error
Browse files Browse the repository at this point in the history
Fix issue where Slack returns upload_error when using webAPI.uploadFile
  • Loading branch information
pvzig authored Jul 1, 2017
2 parents 461de5e + f07b7cf commit 560d164
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Sources/NetworkInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,14 @@ public struct NetworkInterface {
let boundaryEnd = "--\(boundaryConstant)--\r\n"
let contentDispositionString = "Content-Disposition: form-data; name=\"file\"; filename=\"\(filename)\"\r\n"
let contentTypeString = "Content-Type: \(filetype)\r\n\r\n"
let dataEnd = "\r\n"

guard
let boundaryStartData = boundaryStart.data(using: .utf8),
let dispositionData = contentDispositionString.data(using: .utf8),
let contentTypeData = contentTypeString.data(using: .utf8),
let boundaryEndData = boundaryEnd.data(using: .utf8)
let boundaryEndData = boundaryEnd.data(using: .utf8),
let dataEndData = dataEnd.data(using: .utf8)
else {
errorClosure(SlackError.clientNetworkError)
return
Expand All @@ -150,6 +152,7 @@ public struct NetworkInterface {
requestBodyData.append(contentsOf: dispositionData)
requestBodyData.append(contentsOf: contentTypeData)
requestBodyData.append(contentsOf: data)
requestBodyData.append(contentsOf: dataEndData)
requestBodyData.append(contentsOf: boundaryEndData)

request.setValue(contentType, forHTTPHeaderField: "Content-Type")
Expand Down

0 comments on commit 560d164

Please sign in to comment.