如何在iOS swift中不使用api从dropbox下载图像

时间:2017-09-19 11:27:49

标签: ios swift dropbox-api

这是来自Dropbox API资源管理器的dropbox api资源管理器的http请求•下载

POST /2/files/download
Host: https://content.dropboxapi.com
User-Agent: api-explorer-client
Authorization: ACCESS-TOKEN
Dropbox-API-Arg: {"path":"image.jpg"}

我创建了一个Alamofire请求下载,但它没有工作

但是当我创建一个临时链接并尝试下载时,它可以工作。

临时链接下载(工作)代码



let parameters: Parameters = [
            "path": requestedFilePath
        ]
        
        let urlString = AjaxRequestUrlList.getDropBoxTempLink
        Alamofire.request(urlString, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: dropboxHeaderWithContentTypeJSON)
            .LogRequest()
            .responseJSON { response in
                if !response.result.isFailure{
                    var json = JSON(response.result.value!)
                    if json["link"].exists(){
                            Alamofire.download(json["link"].string!, to: destination).responseData { response in
                                if completionHandler != nil{
                                    completionHandler(true)
                                }
                        }
                    }
                    else{
                        if completionHandler != nil{
                            completionHandler(false)
                        }
                    }
                }
                else{
                        if completionHandler != nil{
                        completionHandler(false)
                    }
                }
        }






let dropboxHeaderWithContentTypeJSON: HTTPHeaders = [
    "Authorization": CS_App_Constants.dropboxAccessToken,
    "Content-Type" : "application/json"
    ]




但是如果我直接调用https://content.dropboxapi.com/2/files/download而没有获得临时链接就会失败

0 个答案:

没有答案