Fix regression when sharing files with spaces in the filename (#2624)

This commit is contained in:
Elias Nahum 2019-03-05 11:55:11 -03:00 committed by GitHub
parent d0a4e06397
commit 67fa577695
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,6 +9,17 @@ import UIKit
return Singleton.instance
}
private func buildUploadURL(baseURL: String, channelId: String, fileName: String?) -> URL? {
let urlComponent = NSURLComponents(string: "\(baseURL)/api/v4/files")
let queryChannel = URLQueryItem(name: "channel_id", value: channelId)
let queryFile = URLQueryItem(name: "filename", value: fileName)
urlComponent?.path = "/api/v4/files"
urlComponent?.queryItems = [queryChannel, queryFile]
print("URL TO UPLOAD \(urlComponent?.string ?? "NOT DEFINED")")
return urlComponent?.url
}
public func uploadFiles(baseURL: String, token: String, channelId: String, message: String?, attachments: AttachmentArray<AttachmentItem>, callback: () -> Void) {
let identifier = "mattermost-share-upload-\(UUID().uuidString)"
UploadSessionManager.shared.createUploadSessionData(
@ -24,7 +35,8 @@ import UIKit
for index in 0..<attachments.count {
guard let item = attachments[index] else {return}
let url = URL(string: "\(baseURL)/api/v4/files?channel_id=\(channelId)&filename=\(item.fileName!)")
let url = buildUploadURL(baseURL: baseURL, channelId: channelId, fileName: item.fileName)
var uploadRequest = URLRequest(url: url!)
uploadRequest.httpMethod = "POST"
uploadRequest.addValue("Bearer \(token)", forHTTPHeaderField: "Authorization")