From 2d8454c7117e13cecbf88b7825193ddafd67594e Mon Sep 17 00:00:00 2001 From: Alek Slater Date: Tue, 6 Dec 2016 14:51:48 +0800 Subject: [PATCH] Update DropboxFileProvider.swift Using the same request dict creation method that can be found in the contents method, to avoid error when trying to use copyItem to copy a remote file to a local file destination. --- Sources/DropboxFileProvider.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sources/DropboxFileProvider.swift b/Sources/DropboxFileProvider.swift index 480d54a..8173383 100644 --- a/Sources/DropboxFileProvider.swift +++ b/Sources/DropboxFileProvider.swift @@ -196,13 +196,14 @@ extension DropboxFileProvider: FileProviderOperations { var request = URLRequest(url: url) request.httpMethod = "GET" request.setValue("Bearer \(credential?.password ?? "")", forHTTPHeaderField: "Authorization") - request.setValue("application/json", forHTTPHeaderField: "Content-Type") - let requestDictionary = ["path": correctPath(path)! as NSString] - request.setValue(dictionaryToJSON(requestDictionary), forHTTPHeaderField: "Dropbox-API-Arg") + let requestDictionary = ["path": path] + let requestJson = dictionaryToJSON(requestDictionary as [String : AnyObject]) ?? "" + request.setValue(requestJson, forHTTPHeaderField: "Dropbox-API-Arg") let task = session.downloadTask(with: request, completionHandler: { (cacheURL, response, error) in guard let cacheURL = cacheURL, let httpResponse = response as? HTTPURLResponse , httpResponse.statusCode < 300 else { let code = FileProviderHTTPErrorCode(rawValue: (response as? HTTPURLResponse)?.statusCode ?? -1) - let dbError: FileProviderDropboxError? = code != nil ? FileProviderDropboxError(code: code!, path: path, errorDescription: nil) : nil + let errorData : Data? = nil //Data(contentsOf:cacheURL) // TODO: Figure out how to get error response data for the error description + let dbError : FileProviderDropboxError? = code != nil ? FileProviderDropboxError(code: code!, path: path, errorDescription: String(data: errorData ?? Data(), encoding: .utf8)) : nil completionHandler?(dbError ?? error) return }