イメージをIMAGGA APIにアップロードしようとしていて、プロジェクトのイメージ認識タグを取り戻そうとしましたが、希望するタグを取得できませんでした。私はAlamofireを使用して画像をアップロードしていますが、このエラーとAPI呼び出しのタグはありません。Imagga APIとAlamofireの使用
ここに私が画像をアップロードするために使用した機能があります。 コード:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
defer {
picker.dismiss(animated: true)
}
print(info)
// get the image
guard let image = info[UIImagePickerControllerOriginalImage] as? UIImage else {
return
}
imageView.image = image
let documentDirectory: NSString = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first! as NSString
let imageName = "temp"
let imagePath = documentDirectory.appendingPathComponent(imageName)
if let data = UIImageJPEGRepresentation(image, 80) {
// Save cloned image into document directory
let urlFile = NSURL(string: imagePath)
do {
try data.write(to: urlFile! as URL, options: .atomic)
} catch {
print(error)
}
// Save it's path
localPath = imagePath
}
let imageData = UIImagePNGRepresentation(image)!
//
let headers: HTTPHeaders = [
"Authorization": "Basic YWNjX2MwNDUzYzkzNTEyOGNkYzo0ZmE5MWM4Zjg0MDk1ZGI0NGE2ZjNjODJkNTczZDUxOQ==",
"Accept": "application/json"
]
Alamofire.request("https://httpbin.org/basic-auth/\("acc_c0453c935128cdc")/\("4fa91c8f84095db44a6f3c82d573d519")", parameters: ["url": "http://docs.imagga.com/static/images/docs/sample/japan-605234_1280.jpg"], headers: headers)
.authenticate(user: "acc_c0453c935128cdc", password: "4fa91c8f84095db44a6f3c82d573d519")
.responseJSON { response in
debugPrint(response)
switch(response.result) {
case .success(_):
if let data = response.result.value{
print("YOUR JSON DATA>> \(response.data!)")
}
break
case .failure(_):
print(response.result.error)
break
}
}
}
これはエラーとして表示されています。最終的には成功を収めていますが、イメージがイメージ認識のためにイメージャに送られるかどうかはわかりません。
Error:
URL which has no scheme
Error Domain=NSCocoaErrorDomain Code=518 "The file couldn’t be saved because the specified URL type isn’t supported." UserInfo={NSURL=/var/mobile/Containers/Data/Application/D8A0EE1D-2092-474F-B21A-8A7E0635AD40/Documents/temp}
[Request]: GET https://httpbin.org/basic-auth/acc_c0453c935128cdc/4fa91c8f84095db44a6f3c82d573d519?url=http%3A//docs.imagga.com/static/images/docs/sample/japan-605234_1280.jpg
[Response]: <NSHTTPURLResponse: 0x1702210e0> { URL: https://httpbin.org/basic-auth/acc_c0453c935128cdc/4fa91c8f84095db44a6f3c82d573d519?url=http%3A//docs.imagga.com/static/images/docs/sample/japan-605234_1280.jpg } { status code: 200, headers {
"Access-Control-Allow-Credentials" = true;
"Access-Control-Allow-Origin" = "*";
Connection = "keep-alive";
"Content-Length" = 62;
"Content-Type" = "application/json";
Date = "Tue, 29 Aug 2017 16:42:07 GMT";
Server = "meinheld/0.6.1";
Via = "1.1 vegur";
"X-Powered-By" = Flask;
"X-Processed-Time" = "0.000633001327515";
} }
[Data]: 62 bytes
[Result]: SUCCESS: {
authenticated = 1;
user = "acc_c0453c935128cdc";
}
[Timeline]: Timeline: { "Request Start Time": 525717726.320, "Initial Response Time": 525717728.876, "Request Completed Time": 525717728.882, "Serialization Completed Time": 525717728.889, "Latency": 2.556 secs, "Request Duration": 2.562 secs, "Serialization Duration": 0.006 secs, "Total Duration": 2.569 secs }
YOUR JSON DATA>> 62 bytes
パブリックフォーラムに公開キーを公開しないでください。 – nathan