swift2.3からswift3に移行作業を進めているのですが、
Alamofire4.5.1で画像をアップロードする処理がいまいち分からず困っています。
swift2.3ではこのように書いていました。
Alamofire.upload( "https://object-storage.tyo1.conoha.io/v1/nc_12345/hogehoge/hogehoge.jpeg", method: .put, headers: ["X-Auth-Token": token] as! HTTPHeaders, data: imageData).progress { bytesWritten, totalBytesWritten, totalBytesExpectedToWrite in }.responseString { response in switch response.result { case .Success: print("成功") case .Failure(let error): print("失敗") } }
Conohaのオブジェクトストレージに画像をアップするためPUTでしています。
tokenはオブジェクトストレージのトークンです。
swift3でこのように書いてみました。
let urlString = "https://object-storage.tyo1.conoha.io/v1/nc_12345/hogehoge/hogehoge.jpeg" let headers = ["X-Auth-Token": token] as HTTPHeaders! Alamofire.upload(data:imageData, to: urlString as URLConvertible, method: .put, headers: headers) .responseData { response in }
Ambiguous reference to member 'upload(_:to:method:headers:)'
というエラーで型を明示的に宣言しないといけないのか分かりません。
xcodeは9です
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。