2016-06-08 10 views
0

Es scheint egal, was ich auf iOS meine Dateiübertragung mal aus. Ich habe derzeit kein Android-Gerät zum Testen, aber es funktionierte seit gestern. Ich habe die Dateiübertragung Plugin und Whitelist installiert.ionic2 cordova Dateiübertragung Plugin Timeout Fehlercode 3

Ionic Framework Version: 2.0.0-beta.8, ionische CLI Version: 2.0.0-beta.30, Ionic App Lib Version: 2.0.0-beta.16 Xcode Version: Xcode 7.3.1

Hier ist mein Code:

upload = (image: string) : void => { 
    let ft = new Transfer(); 
    let filename = image.substr(image.lastIndexOf('/')+1)+'.jpg'; 
    let options = { 
    fileKey: 'file', 
    fileName: filename, 
    mimeType: 'image/jpeg', 
    chunkedMode: false, 
    headers: { 
     'Content-Type' : undefined 
    }, 
    params: { 
     fileName: filename, 
     apikey: "mykey" 
    } 
    }; 
    ft.upload(image, "https://api.ocr.space/parse/image", options, false) 
    .then((result: any) => { 
    this.success(result); 
    }).catch((error: any) => { 
    this.failed(error); 
    }); 
} 

Es mal aus, jedes mal und gibt dieses Ergebnis:

[6311:2681244] -[CDVFileTransfer requestForUploadCommand:fileData:] 

[Line 224] fileData length: 68706 

[6311:2682532] FileTransferError { 
    body = ""; 
    code = 3; 
    "http_status" = 0; 
    source = "file:///var/mobile/Containers/Data/Application/372A03D7-653A-45D8-B59A-EA34252E4AF3/tmp/cdv_photo_006.jpg"; 
    target = "https://api.ocr.space/parse/image"; 
} 

[6311:2682532] File Transfer Error: The request timed out. 
+0

Könnten Sie 'Content-Type' gesetzt: ‚image/jpeg 'in den Kopfzeilen und einmal versuchen? – Gandhi

Antwort

0

Es scheint, mit der ein Problem gewesen zu sein Endpunkt. Hier ist eine Kopie des Woking-Upload-Codes für jeden, der es sucht.

upload = (image: string) : void => { 
let ft = new Transfer(); 
let options = new FileUploadOptions(); 

options.fileKey="file"; 
options.fileName=image.substr(image.lastIndexOf('/')+1)+'.jpg'; 
options.mimeType="text/plain"; 

let params = new Object(); 
params.apikey = "helloworld"; 
options.params = params; 

//ft.onProgress(this.onProgress); 
ft.upload(image, "https://apifree2.ocr.space//parse/image", options, false) 
.then((result: any) => { 
    this.success(result); 
}).catch((error: any) => { 
    this.failed(error); 
}); 


} 
success = (result: any) : void => { 
    console.log(result); 
} 
failed = (err: any) : void => { 
    let code = err.code; 
    alert("Failed to upload image. Code: " + code); 
} 
1

Wie für iOS 9 und höher, müssen Sie AppTransportSecurity in XCode hinzufügen, bevor Sie Verbindung mit HTTP ermöglichen veröffentlichen. Fügen Sie bei XCode einen Schlüssel in info.plist hinzu. Die Schritte, die ich gefolgt sind:

  1. Eröffnet meine Projekte info.plist Datei
  2. einen Schlüssel hinzugefügt NSAppTransportSecurity als Wörterbuch bezeichnet.
  3. Ein Unterschlüssel namens NSAllowsArbitraryLoads als Boolescher Wert wurde hinzugefügt und der Wert auf YES gesetzt. Oder wie unten info.plist mit Code ändern:

Sie müssen sich ändern yourserver.com mit Ihrem eigenen URL für die Dateiübertragung

<key>NSAppTransportSecurity</key> 
<dict> 
    <key>NSExceptionDomains</key> 
    <dict> 
    <key>yourserver.com</key> 
    <dict> 
     <!--Include to allow subdomains--> 
     <key>NSIncludesSubdomains</key> 
     <true/> 
     <!--Include to allow HTTP requests--> 
     <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> 
     <true/> 
     <!--Include to specify minimum TLS version--> 
     <key>NSTemporaryExceptionMinimumTLSVersion</key> 
     <string>TLSv1.1</string> 
    </dict> 
    </dict> 
</dict> 
Verwandte Themen