diff --git a/RELEASENOTES.md b/RELEASENOTES.md index d2d6946..97e4d52 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -97,3 +97,19 @@ * CB-5980 Updated version and RELEASENOTES.md for release 0.4.1 ### 0.4.5 + +### 0.4.5 (Aug 06, 2014) +* Upload parameters out of order +* **FirefoxOS** initial implementation +* CB-6781: Expose FileTransferError.exception to application +* CB-6928: Add new error code to documentation +* CB-6928: Handle 304 status code +* CB-6928: Open output stream only if it's necessary. +* [BlackBerry10] Minor doc correction +* CB-6127 Updated translations for docs +* [Windows8] upload uses the provided fileName or the actual fileName +* CB-2420 [Windows8] honor fileKey and param options. This closes #15 +* CB-6781: Update new docs to match AlexNennker's changes in PR30 +* CB-6781: Continue previous commit with one new instance (This closes #30) +* CB-6781: add the exception text to the error object +* CB-6890: Fix pluginManager access for 4.0.x branch diff --git a/doc/de/index.md b/doc/de/index.md index 4720fad..095c616 100644 --- a/doc/de/index.md +++ b/doc/de/index.md @@ -31,12 +31,15 @@ Dieses Plugin ermöglicht Ihnen zum Hochladen und Herunterladen von Dateien. * Amazon Fire OS * Android * BlackBerry 10 +* Firefox OS ** * iOS * Windows Phone 7 und 8 * * Windows 8 * * *Unterstützen nicht `onprogress` noch `abort()` * +** *Unterstützen keine `onprogress` * + # FileTransfer Das `FileTransfer` Objekt bietet eine Möglichkeit zum Hochladen von Dateien, die mithilfe einer HTTP-Anforderung für mehrteiligen POST sowie Informationen zum Herunterladen von Dateien sowie. @@ -65,8 +68,6 @@ Das `FileTransfer` Objekt bietet eine Möglichkeit zum Hochladen von Dateien, di * **ErrorCallback**: ein Rückruf, der ausgeführt wird, tritt ein Fehler beim Abrufen der `Metadata` . Aufgerufene mit einem `FileTransferError` Objekt. *(Funktion)* -* **TrustAllHosts**: Optionaler Parameter, wird standardmäßig auf `false` . Wenn legen Sie auf `true` , es akzeptiert alle Sicherheitszertifikate. Dies ist nützlich, da Android selbstsignierte Zertifikate ablehnt. Nicht für den produktiven Einsatz empfohlen. Auf Android und iOS unterstützt. *(Boolean)* - * **Optionen**: optionale Parameter *(Objekt)*. Gültige Schlüssel: * **FileKey**: der Name des Form-Elements. Wird standardmäßig auf `file` . (DOM-String und enthält) @@ -76,6 +77,8 @@ Das `FileTransfer` Objekt bietet eine Möglichkeit zum Hochladen von Dateien, di * **ChunkedMode**: ob die Daten in "Chunked" streaming-Modus hochladen. Wird standardmäßig auf `true` . (Boolean) * **Header**: eine Karte von Header-Name-Header-Werte. Verwenden Sie ein Array, um mehr als einen Wert anzugeben. (Objekt) +* **TrustAllHosts**: Optionaler Parameter, wird standardmäßig auf `false` . Wenn legen Sie auf `true` , es akzeptiert alle Sicherheitszertifikate. Dies ist nützlich, da Android selbstsignierte Zertifikate ablehnt. Nicht für den produktiven Einsatz empfohlen. Auf Android und iOS unterstützt. *(Boolean)* + ### Beispiel // !! Assumes variable fileURL contains a valid URL to a text file on the device, diff --git a/doc/es/index.md b/doc/es/index.md index 7b56036..4e27482 100644 --- a/doc/es/index.md +++ b/doc/es/index.md @@ -31,12 +31,15 @@ Este plugin te permite cargar y descargar archivos. * Amazon fuego OS * Android * BlackBerry 10 +* Firefox OS ** * iOS * Windows Phone 7 y 8 * * Windows 8 * * *No son compatibles con `onprogress` ni `abort()` * +** *No son compatibles con `onprogress` * + # File Transfer El `FileTransfer` objeto proporciona una manera de subir archivos mediante una solicitud HTTP de POST varias parte y para descargar archivos. @@ -65,8 +68,6 @@ El `FileTransfer` objeto proporciona una manera de subir archivos mediante una s * **errorCallback**: una devolución de llamada que se ejecuta si se produce un error recuperar la `Metadata` . Invocado con un `FileTransferError` objeto. *(Función)* -* **trustAllHosts**: parámetro opcional, por defecto es `false` . Si establece en `true` , acepta todos los certificados de seguridad. Esto es útil ya que Android rechaza certificados autofirmados seguridad. No se recomienda para uso productivo. Compatible con iOS y Android. *(boolean)* - * **Opciones**: parámetros opcionales *(objeto)*. Teclas válidas: * **fileKey**: el nombre del elemento de formulario. Por defecto es `file` . (DOMString) @@ -76,6 +77,8 @@ El `FileTransfer` objeto proporciona una manera de subir archivos mediante una s * **chunkedMode**: Si desea cargar los datos en modo de transmisión fragmentado. Por defecto es `true` . (Boolean) * **cabeceras**: un mapa de valores de encabezado nombre/cabecera. Utilice una matriz para especificar más de un valor. (Objeto) +* **trustAllHosts**: parámetro opcional, por defecto es `false` . Si establece en `true` , acepta todos los certificados de seguridad. Esto es útil ya que Android rechaza certificados autofirmados seguridad. No se recomienda para uso productivo. Compatible con iOS y Android. *(boolean)* + ### Ejemplo // !! Assumes variable fileURL contains a valid URL to a text file on the device, diff --git a/doc/fr/index.md b/doc/fr/index.md index 1fb8b25..39978c9 100644 --- a/doc/fr/index.md +++ b/doc/fr/index.md @@ -31,15 +31,18 @@ Ce plugin vous permet de télécharger des fichiers. * Amazon Fire OS * Android * BlackBerry 10 +* Firefox OS ** * iOS * Windows Phone 7 et 8 * * Windows 8 * * *Ne supportent pas `onprogress` ni `abort()` * +** *Ne prennent pas en charge `onprogress` * + # Transfert de fichiers -L'objet `FileTransfer` fournit un moyen de tranférer des fichiers sur un serveur HTTP avec une requête multi-part POST, et aussi pour télécharger des fichiers. +Le `FileTransfer` objet fournit un moyen de télécharger des fichiers à l'aide d'une requête HTTP de la poste plusieurs partie et pour télécharger des fichiers aussi bien. ## Propriétés @@ -65,16 +68,16 @@ L'objet `FileTransfer` fournit un moyen de tranférer des fichiers sur un serveu * **errorCallback** : callback d'erreur s'exécutant si une erreur survient lors de la récupération de l'objet `Metadata` . Appelée avec un objet `FileTransferError`. *(Function)* -* **trustAllHosts** : paramètre facultatif, sa valeur par défaut est `false`. Si sa valeur est réglée à `true`, tous les certificats de sécurité sont acceptés. Ceci peut être utile car Android rejette les certificats auto-signés. N'est pas recommandé pour une utilisation en production. Supporté sous Android et iOS. *(boolean)* - * **options**: paramètres facultatifs *(objet)*. Clés valides : - * **fileKey** : le nom de l'élément form. La valeur par défaut est `file`. (DOMString) - * **fileName** : le nom de fichier à utiliser pour l'enregistrement sur le serveur. La valeur par défaut est `image.jpg`. (DOMString) - * **mimeType** : le type mime des données à envoyer. La valeur par défaut est `image/jpeg`. (DOMString) - * **params** : un ensemble de paires clé/valeur facultative à passer dans la requête HTTP. (Objet) - * **chunkedMode** : s'il faut transmettre ou non les données en mode streaming de bloc. La valeur par défaut est `true`. (Boolean) - * **headers** : un objet représentant les noms et valeurs d'en-têtes à transmettre. Utiliser un tableau permet de spécifier plusieurs valeurs. (Objet) + * **fileKey**: le nom de l'élément form. Valeur par défaut est `file` . (DOMString) + * **fileName**: le nom de fichier à utiliser lorsque vous enregistrez le fichier sur le serveur. Valeur par défaut est `image.jpg` . (DOMString) + * **type MIME**: le type mime des données à télécharger. Valeur par défaut est `image/jpeg` . (DOMString) + * **params**: un ensemble de paires clé/valeur facultative pour passer dans la requête HTTP. (Objet) + * **chunkedMode**: s'il faut télécharger les données en mode streaming mémorisé en bloc. Valeur par défaut est `true` . (Boolean) + * **en-têtes**: une carte des valeurs d'en-tête en-tête/nom. Un tableau permet de spécifier plusieurs valeurs. (Objet) + +* **trustAllHosts**: paramètre facultatif, valeur par défaut est `false` . Si la valeur `true` , il accepte tous les certificats de sécurité. Ceci est utile car Android rejette des certificats auto-signés. Non recommandé pour une utilisation de production. Supporté sur Android et iOS. *(boolean)* ### Exemple @@ -146,7 +149,7 @@ L'objet `FileTransfer` fournit un moyen de tranférer des fichiers sur un serveu ## FileUploadResult -Un objet `FileUploadResult` est passé à la callback de succès de la méthode `upload()` de l'objet `FileTransfer`. +A `FileUploadResult` objet est passé au rappel de succès la `FileTransfer` de l'objet `upload()` méthode. ### Propriétés @@ -210,7 +213,7 @@ Un objet `FileUploadResult` est passé à la callback de succès de la méthode ## abort -Abandonne un transfert en cours. Un objet FileTransferError avec un code d'erreur FileTransferError.ABORT_ERR est passé à la callback d'erreur onerror. +Abandonne un transfert en cours. Le rappel onerror est passé à un objet FileTransferError qui a un code d'erreur de FileTransferError.ABORT_ERR. ### Exemple @@ -240,7 +243,7 @@ Abandonne un transfert en cours. Un objet FileTransferError avec un code d'erreu ## FileTransferError -Un objet `FileTransferError` est passé à une callback d'erreur lorsqu'une erreur survient. +A `FileTransferError` objet est passé à un rappel d'erreur lorsqu'une erreur survient. ### Propriétés @@ -264,21 +267,21 @@ Un objet `FileTransferError` est passé à une callback d'erreur lorsqu'une erre ## Backwards Compatibility Notes -Les versions précédentes de ce plugin accepte seulement les chemins de fichiers périphérique absolus comme source pour les chargement, ou comme cible pour les téléchargements. Ces chemins sont généralement de la forme +Les versions précédentes de ce plugin n'accepterait périphérique--fichier-chemins d'accès absolus comme source pour les téléchargements, ou comme cible pour les téléchargements. Ces chemins seraient généralement de la forme /var/mobile/Applications//Documents/path/to/file (iOS) /storage/emulated/0/path/to/file (Android) -Pour la compatibilité ascendante, ces chemins sont toujours acceptés, et si votre application a enregistré des chemins comme ceux-ci dans un stockage persistant, alors ils peuvent continuer à être utilisé. +Pour vers l'arrière la compatibilité, ces chemins sont toujours acceptés, et si votre application a enregistré des chemins comme celles-ci dans un stockage persistant, alors ils peuvent continuer à être utilisé. -Ces chemins ont été précédemment exposés dans la propriété `fullPath` de `FileEntry` et objets `DirectoryEntry` retournés par le fichier plugin. Nouvelles versions du fichier plugin, cependant, ne plus exposer ces chemins à JavaScript. +Ces chemins ont été précédemment exposés dans le `fullPath` propriété de `FileEntry` et `DirectoryEntry` les objets retournés par le fichier plugin. Nouvelles versions du fichier plugin, cependant, ne plus exposent ces chemins à JavaScript. -Si vous migrez vers une nouvelle version du fichier (1.0.0 ou plus récent) et que vous utilisiez précédemment `entry.fullPath` en tant qu'arguments à `download()` ou `upload()`, alors vous aurez besoin de modifier votre code pour utiliser le système de fichiers URL à la place. +Si vous migrez vers une nouvelle (1.0.0 ou plus récent) version de fichier et vous avez précédemment utilisé `entry.fullPath` comme arguments à `download()` ou `upload()` , alors vous aurez besoin de modifier votre code pour utiliser le système de fichiers URL au lieu de cela. -`FileEntry.toURL()` et `DirectoryEntry.toURL()` retournent une URL de système de fichier de formulaire +`FileEntry.toURL()`et `DirectoryEntry.toURL()` retournent une URL de système de fichiers du formulaire cdvfile://localhost/persistent/path/to/file -qui peut être utilisé à la place du chemin d'accès absolu au fichier dans les méthodes `download()` et `upload()`. \ No newline at end of file +qui peut être utilisé à la place le chemin d'accès absolu au fichier dans les deux `download()` et `upload()` méthodes. \ No newline at end of file diff --git a/doc/index.md b/doc/index.md index 997d273..e93a8f3 100644 --- a/doc/index.md +++ b/doc/index.md @@ -30,12 +30,15 @@ This plugin allows you to upload and download files. - Amazon Fire OS - Android - BlackBerry 10 +- Firefox OS** - iOS - Windows Phone 7 and 8* - Windows 8* \* _Do not support `onprogress` nor `abort()`_ +\** _Do not support `onprogress`_ + # FileTransfer The `FileTransfer` object provides a way to upload files using an HTTP @@ -66,8 +69,6 @@ __Parameters__: - __errorCallback__: A callback that executes if an error occurs retrieving the `Metadata`. Invoked with a `FileTransferError` object. _(Function)_ -- __trustAllHosts__: Optional parameter, defaults to `false`. If set to `true`, it accepts all security certificates. This is useful since Android rejects self-signed security certificates. Not recommended for production use. Supported on Android and iOS. _(boolean)_ - - __options__: Optional parameters _(Object)_. Valid keys: - __fileKey__: The name of the form element. Defaults to `file`. (DOMString) - __fileName__: The file name to use when saving the file on the server. Defaults to `image.jpg`. (DOMString) @@ -75,6 +76,8 @@ __Parameters__: - __params__: A set of optional key/value pairs to pass in the HTTP request. (Object) - __chunkedMode__: Whether to upload the data in chunked streaming mode. Defaults to `true`. (Boolean) - __headers__: A map of header name/header values. Use an array to specify more than one value. (Object) + +- __trustAllHosts__: Optional parameter, defaults to `false`. If set to `true`, it accepts all security certificates. This is useful since Android rejects self-signed security certificates. Not recommended for production use. Supported on Android and iOS. _(boolean)_ ### Example diff --git a/doc/it/index.md b/doc/it/index.md index 7f8717c..be17a9b 100644 --- a/doc/it/index.md +++ b/doc/it/index.md @@ -31,12 +31,15 @@ Questo plugin permette di caricare e scaricare file. * Amazon fuoco OS * Android * BlackBerry 10 +* Firefox OS * * * iOS * Windows Phone 7 e 8 * * Windows 8 * * *Non supportano `onprogress` né `abort()` * +* * *Non supportano `onprogress` * + # FileTransfer Il `FileTransfer` oggetto fornisce un modo per caricare i file utilizzando una richiesta HTTP di POST più parte e scaricare file pure. @@ -65,8 +68,6 @@ Il `FileTransfer` oggetto fornisce un modo per caricare i file utilizzando una r * **errorCallback**: un callback che viene eseguito se si verifica un errore recuperando il `Metadata` . Invocato con un `FileTransferError` oggetto. *(Funzione)* -* **trustAllHosts**: parametro opzionale, valore predefinito è `false` . Se impostata su `true` , accetta tutti i certificati di sicurezza. Questo è utile poiché Android respinge i certificati autofirmati sicurezza. Non raccomandato per uso in produzione. Supportato su Android e iOS. *(boolean)* - * **opzioni**: parametri facoltativi *(oggetto)*. Chiavi valide: * **fileKey**: il nome dell'elemento form. Valore predefinito è `file` . (DOMString) @@ -76,6 +77,8 @@ Il `FileTransfer` oggetto fornisce un modo per caricare i file utilizzando una r * **chunkedMode**: se a caricare i dati in modalità streaming chunked. Valore predefinito è `true` . (Boolean) * **intestazioni**: mappa di valori nome/intestazione intestazione. Utilizzare una matrice per specificare più valori. (Oggetto) +* **trustAllHosts**: parametro opzionale, valore predefinito è `false` . Se impostata su `true` , accetta tutti i certificati di sicurezza. Questo è utile poiché Android respinge i certificati autofirmati sicurezza. Non raccomandato per uso in produzione. Supportato su Android e iOS. *(boolean)* + ### Esempio // !! Assumes variable fileURL contains a valid URL to a text file on the device, diff --git a/doc/ja/index.md b/doc/ja/index.md index fbdd728..d8aefcb 100644 --- a/doc/ja/index.md +++ b/doc/ja/index.md @@ -31,12 +31,15 @@ * アマゾン火 OS * アンドロイド * ブラックベリー 10 +* Firefox の OS * * * iOS * Windows Phone 7 と 8 * * Windows 8 * **サポートしていない `onprogress` も `abort()` * +* **サポートしていない `onprogress` * + # ファイル転送 `FileTransfer`オブジェクトはマルチパートのポスト、HTTP 要求を使用してファイルをアップロードして同様にファイルをダウンロードする方法を提供します。 @@ -65,8 +68,6 @@ * **解り**: エラー取得が発生した場合に実行されるコールバック、 `Metadata` 。呼び出されると、 `FileTransferError` オブジェクト。*(機能)* -* **trustAllHosts**: 省略可能なパラメーターは、デフォルト `false` 。 場合設定 `true` 、セキュリティ証明書をすべて受け付けます。 これは Android の自己署名入りセキュリティ証明書を拒否するので便利です。 運用環境で使用しないでください。 Android と iOS でサポートされています。 *(ブール値)* - * **オプション**: 省略可能なパラメーター *(オブジェクト)*。有効なキー: * **fileKey**: フォーム要素の名前。既定値は `file` です。(,) @@ -76,6 +77,8 @@ * **chunkedMode**: チャンク ストリーミング モードでデータをアップロードするかどうか。既定値は `true` です。(ブール値) * **ヘッダー**: ヘッダーの名前/ヘッダー値のマップ。1 つ以上の値を指定するには、配列を使用します。(オブジェクト) +* **trustAllHosts**: 省略可能なパラメーターは、デフォルト `false` 。 場合設定 `true` 、セキュリティ証明書をすべて受け付けます。 これは Android の自己署名入りセキュリティ証明書を拒否するので便利です。 運用環境で使用しないでください。 Android と iOS でサポートされています。 *(ブール値)* + ### 例 // !! Assumes variable fileURL contains a valid URL to a text file on the device, diff --git a/doc/ko/index.md b/doc/ko/index.md index 5cadffb..5c76fd2 100644 --- a/doc/ko/index.md +++ b/doc/ko/index.md @@ -31,12 +31,15 @@ * 아마존 화재 운영 체제 * 안 드 로이드 * 블랙베리 10 +* 파이어 폭스 OS * * * iOS * Windows Phone 7과 8 * * 윈도우 8 * * *를 지원 하지 않는 `onprogress` 도 `abort()` * +* * *를 지원 하지 않는 `onprogress` * + # FileTransfer `FileTransfer`개체는 HTTP 다중 파트 POST 요청을 사용 하 여 파일을 업로드 하 고 뿐만 아니라 파일을 다운로드 하는 방법을 제공 합니다. @@ -65,8 +68,6 @@ * **errorCallback**: 콜백 검색에 오류가 발생 하면 실행 되는 `Metadata` . 로 호출을 `FileTransferError` 개체. *(기능)* -* **trustAllHosts**: 선택적 매개 변수는 기본적으로 `false` . 만약 설정 `true` , 그것은 모든 보안 인증서를 허용 합니다. 이 안 드 로이드 자체 서명 된 보안 인증서를 거부 하기 때문에 유용 합니다. 프로덕션 환경에서 사용 권장 되지 않습니다. 안 드 로이드와 iOS에서 지원. *(부울)* - * **옵션**: 선택적 매개 변수 *(개체)*. 유효한 키: * **fileKey**: form 요소의 이름. 기본값은 `file` . (DOMString) @@ -76,6 +77,8 @@ * **chunkedMode**: 청크 스트리밍 모드에서 데이터 업로드를 합니다. 기본값은 `true` . (부울) * **헤더**: 헤더 이름/헤더 값의 지도. 배열을 사용 하 여 하나 이상의 값을 지정 합니다. (개체) +* **trustAllHosts**: 선택적 매개 변수는 기본적으로 `false` . 만약 설정 `true` , 그것은 모든 보안 인증서를 허용 합니다. 이 안 드 로이드 자체 서명 된 보안 인증서를 거부 하기 때문에 유용 합니다. 프로덕션 환경에서 사용 권장 되지 않습니다. 안 드 로이드와 iOS에서 지원. *(부울)* + ### 예를 들어 // !! Assumes variable fileURL contains a valid URL to a text file on the device, diff --git a/doc/pl/index.md b/doc/pl/index.md index 4860969..e3b38cd 100644 --- a/doc/pl/index.md +++ b/doc/pl/index.md @@ -30,13 +30,16 @@ Plugin pozwala na przesyłanie i pobieranie plików. * Amazon ogień OS * Android -* Jeżyna 10 * +* Jeżyna 10 +* Firefox OS ** * iOS * Windows Phone 7 i 8 * * Windows 8 * * *Nie obsługują `onprogress` ani `abort()` * +** *Nie obsługują `onprogress` * + # FileTransfer `FileTransfer`Obiekt zapewnia sposób wgrać pliki przy użyciu żądania HTTP wieloczęściowe POST i pobierania plików, jak również. @@ -65,8 +68,6 @@ Plugin pozwala na przesyłanie i pobieranie plików. * **errorCallback**: wywołanie zwrotne, które wykonuje, jeżeli wystąpi błąd pobierania `Metadata` . Wywołany z `FileTransferError` obiektu. *(Funkcja)* -* **trustAllHosts**: parametr opcjonalny, domyślnie `false` . Jeśli zestaw `true` , to akceptuje wszystkie certyfikaty bezpieczeństwa. Jest to przydatne, ponieważ Android odrzuca Certyfikaty samopodpisane. Nie zaleca się do użytku produkcyjnego. Obsługiwane na Androida i iOS. *(wartość logiczna)* - * **Opcje**: parametry opcjonalne *(obiektu)*. Ważne klucze: * **fileKey**: nazwa elementu form. Domyślnie `file` . (DOMString) @@ -76,6 +77,8 @@ Plugin pozwala na przesyłanie i pobieranie plików. * **chunkedMode**: czy przekazać dane w trybie pakietowego przesyłania strumieniowego. Domyślnie `true` . (Wartość logiczna) * **nagłówki**: Mapa wartości Nazwa/nagłówka nagłówek. Aby określić więcej niż jedną wartość, należy użyć tablicę. (Obiekt) +* **trustAllHosts**: parametr opcjonalny, domyślnie `false` . Jeśli zestaw `true` , to akceptuje wszystkie certyfikaty bezpieczeństwa. Jest to przydatne, ponieważ Android odrzuca Certyfikaty samopodpisane. Nie zaleca się do użytku produkcyjnego. Obsługiwane na Androida i iOS. *(wartość logiczna)* + ### Przykład // !! Assumes variable fileURL contains a valid URL to a text file on the device, @@ -192,7 +195,7 @@ A `FileUploadResult` obiekt jest przekazywany do funkcji callback sukces z `File uri, fileURL, function(entry) { - console.log("download complete: " + entry.fullPath); + console.log("download complete: " + entry.toURL()); }, function(error) { console.log("download error source " + error.source); @@ -252,13 +255,15 @@ A `FileTransferError` obiekt jest przekazywany do wywołania zwrotnego błąd, g * **HTTP_STATUS**: kod stanu HTTP. Ten atrybut jest dostępna tylko po otrzymaniu kodu odpowiedzi z połączenia HTTP. (Liczba) +* **wyjątek**: albo e.getMessage lub e.toString (String) + ### Stałe -* `FileTransferError.FILE_NOT_FOUND_ERR` -* `FileTransferError.INVALID_URL_ERR` -* `FileTransferError.CONNECTION_ERR` -* `FileTransferError.ABORT_ERR` -* `FileTransferError.NOT_MODIFIED_ERR` +* 1 = `FileTransferError.FILE_NOT_FOUND_ERR` +* 2 = `FileTransferError.INVALID_URL_ERR` +* 3 = `FileTransferError.CONNECTION_ERR` +* 4 = `FileTransferError.ABORT_ERR` +* 5 = `FileTransferError.NOT_MODIFIED_ERR` ## Do tyłu zgodności stwierdza diff --git a/doc/ru/index.md b/doc/ru/index.md index de7c309..5cb6d40 100644 --- a/doc/ru/index.md +++ b/doc/ru/index.md @@ -31,12 +31,15 @@ * Amazon Fire ОС * Android * BlackBerry 10 +* Firefox OS ** * iOS * Windows Phone 7 и 8 * * Windows 8 * * *Не поддерживают `onprogress` , ни `abort()` * +** *Не поддерживает `onprogress` * + # FileTransfer `FileTransfer`Объект предоставляет способ для загрузки файлов с помощью нескольких частей запроса POST HTTP и для загрузки файлов, а также. @@ -65,17 +68,17 @@ * **errorCallback**: обратного вызова, который выполняется в случае получения ошибки `Metadata` . Вызываемый с `FileTransferError` объект. *(Функция)* -* **trustAllHosts**: необязательный параметр, по умолчанию равен `false` . Если значение `true` , она принимает все сертификаты безопасности. Это полезно, поскольку Android отвергает самозаверяющие сертификаты. Не рекомендуется для использования в производстве. Поддерживается на Android и iOS. *(логическое значение)* - * **опции**: необязательные параметры *(объект)*. Допустимые ключи: * **fileKey**: имя элемента form. По умолчанию `file` . (DOMString) * **имя файла**: имя файла для использования при сохранении файла на сервере. По умолчанию `image.jpg` . (DOMString) - * **тип MIME**: тип mime данных для загрузки. По умолчанию `image/jpeg` . (DOMString) + * **mimeType**: mime-тип данных для загрузки. По умолчанию `image/jpeg` . (DOMString) * **params**: набор пар дополнительный ключ/значение для передачи в HTTP-запросе. (Объект) - * **chunkedMode**: следует ли загружать данные в фрагментах потоковом режиме. По умолчанию `true` . (Логическое значение) + * **chunkedMode**: следует ли загружать данные в фрагментарности потоковом режиме. По умолчанию `true` . (Логическое значение) * **заголовки**: Карта значений заголовок имя заголовка. Используйте массив для указания более одного значения. (Объект) +* **trustAllHosts**: необязательный параметр, по умолчанию `false` . Если значение `true` , она принимает все сертификаты безопасности. Это полезно, поскольку Android отвергает самозаверяющие сертификаты. Не рекомендуется для использования в производстве. Поддерживается на Android и iOS. *(логическое значение)* + ### Пример // !! Assumes variable fileURL contains a valid URL to a text file on the device, @@ -146,7 +149,7 @@ ## FileUploadResult -Объект `FileUploadResult` передается на успех обратного вызова метода `upload()` объекта `FileTransfer`. +A `FileUploadResult` объект передается методу обратного вызова успех `FileTransfer` объекта `upload()` метод. ### Свойства @@ -240,7 +243,7 @@ ## FileTransferError -A `FileTransferError` объект передается при ошибке обратного вызова при возникновении ошибки. +A `FileTransferError` при ошибке обратного вызова передается объект, при возникновении ошибки. ### Свойства diff --git a/doc/zh/index.md b/doc/zh/index.md index b54fa2c..fb05a5e 100644 --- a/doc/zh/index.md +++ b/doc/zh/index.md @@ -31,15 +31,18 @@ * 亞馬遜火 OS * Android 系統 * 黑莓 10 +* 火狐瀏覽器作業系統 * * * iOS * Windows Phone 7 和 8 * * Windows 8 * **不支援 `onprogress` ,也不 `abort()` * +* **不支援 `onprogress` * + # 檔案傳輸 -`FileTransfer`物件提供一種方法來使用 HTTP 多部分 POST 請求的檔上傳和下載檔案,以及。 +`FileTransfer`物件提供一種方法使用 HTTP 多部分 POST 請求的檔上傳和下載檔案,以及。 ## 屬性 @@ -65,16 +68,16 @@ * **errorCallback**: 回檔的執行如果出現檢索錯誤 `Metadata` 。調用與 `FileTransferError` 物件。*(函數)* -* **trustAllHosts**: 可選參數,預設值為 `false` 。 如果設置為 `true` ,它可以接受的所有安全證書。 由於 Android 拒絕自行簽署式安全證書,這非常有用。 不建議供生產使用。 在 Android 和 iOS 上受支援。 *(布林值)* - * **選項**: 可選參數*(物件)*。有效的金鑰: * **fileKey**: 表單元素的名稱。預設值為 `file` 。() DOMString * **檔案名**: 要保存在伺服器上的檔時使用的檔案名稱。預設值為 `image.jpg` 。() DOMString * **mimeType**: 要上傳的資料的 mime 類型。預設值為 `image/jpeg` 。() DOMString - * **params**: 一組可選的鍵/值對中的 HTTP 要求的傳遞。(物件) + * **params**: 一組可選的鍵/值對在 HTTP 要求中傳遞。(物件) * **chunkedMode**: 是否要分塊流式處理模式中的資料上載。預設值為 `true` 。(布林值) - * **標題**: 一張地圖的標頭名稱/標頭值。使用陣列來指定多個值。(物件) + * **標題**: 地圖的標頭名稱/標頭值。使用陣列來指定多個值。(物件) + +* **trustAllHosts**: 可選參數,預設值為 `false` 。 如果設置為 `true` ,它接受的所有安全證書。 這是有用的因為 android 系統拒絕自簽名的安全證書。 不建議供生產使用。 支援 Android 和 iOS。 *(布林值)* ### 示例 @@ -240,7 +243,7 @@ A `FileUploadResult` 物件傳遞給成功回檔的 `FileTransfer` 物件的 `up ## FileTransferError -A `FileTransferError` 物件傳遞到錯誤回檔時出現錯誤。 +A `FileTransferError` 物件被傳遞給一個錯誤回呼函數時出現錯誤。 ### 屬性 @@ -264,21 +267,21 @@ A `FileTransferError` 物件傳遞到錯誤回檔時出現錯誤。 ## 向後相容性注意到 -以前版本的這個外掛程式將只接受設備絕對檔路徑作為源的上載,或為下載的目標。這些路徑通常將表單的 +以前版本的這個外掛程式才會接受設備-絕對檔路徑的源上傳,或作為下載的目標。這些路徑通常會在表單 /var/mobile/Applications//Documents/path/to/file (iOS) /storage/emulated/0/path/to/file (Android) -為向後相容性,這些路徑仍被接受,和如果您的應用程式已錄得像這些持久性存儲區中的路徑,然後他們可以繼續使用。 +為向後相容性,這些路徑仍被接受,和如果您的應用程式記錄了像這些在持久性存儲的路徑,然後他們可以繼續使用。 -這些路徑以前被暴露在 `fullPath` 屬性的 `FileEntry` 和 `DirectoryEntry` 由檔外掛程式返回的物件。 新版本的檔的外掛程式,不過,不再公開這些 JavaScript 的路徑。 +這些路徑被以前暴露在 `fullPath` 屬性的 `FileEntry` 和 `DirectoryEntry` 由檔外掛程式返回的物件。 新版本的檔的外掛程式,不過,不再公開這些 JavaScript 的路徑。 -如果您要升級到一個新的 (1.0.0 或更高版本) 版本的檔,和你以前一直在使用 `entry.fullPath` 作為的參數 `download()` 或 `upload()` ,那麼您將需要更改您的代碼,而使用的檔案系統的 Url。 +如果您升級到一個新 (1.0.0 或更高版本) 版本的檔,和你以前一直在使用 `entry.fullPath` 作為的參數 `download()` 或 `upload()` ,那麼你將需要更改代碼以使用檔案系統的 Url 來代替。 `FileEntry.toURL()`和 `DirectoryEntry.toURL()` 返回的表單檔案系統 URL cdvfile://localhost/persistent/path/to/file -可以使用在中兩者的絕對檔路徑位置 `download()` 和 `upload()` 方法。 \ No newline at end of file +其中可代替的絕對檔路徑在兩個 `download()` 和 `upload()` 的方法。 \ No newline at end of file diff --git a/plugin.xml b/plugin.xml index a0e585e..764073b 100644 --- a/plugin.xml +++ b/plugin.xml @@ -21,7 +21,7 @@ + version="0.4.6-dev"> File Transfer Cordova File Transfer Plugin Apache 2.0 @@ -144,4 +144,14 @@ + + + + + + + + + + diff --git a/tests/plugin.xml b/tests/plugin.xml new file mode 100644 index 0000000..0830c4a --- /dev/null +++ b/tests/plugin.xml @@ -0,0 +1,30 @@ + + + + + Cordova File Transfer Plugin Tests + Apache 2.0 + + + + diff --git a/test/tests.js b/tests/tests.js similarity index 96% rename from test/tests.js rename to tests/tests.js index 6f6539c..3aa0b94 100644 --- a/test/tests.js +++ b/tests/tests.js @@ -524,6 +524,9 @@ exports.defineAutoTests = function () { } catch (e) { expect(obj).not.toBeNull('returned data from server should be valid json'); } + expect(lastProgressEvent).not.toBeNull('expected progress events'); + expect(lastProgressEvent.loaded).toBeGreaterThan(1, 'loaded'); + expect(lastProgressEvent.total).not.toBeLessThan(lastProgressEvent.loaded); done(); }; @@ -544,34 +547,6 @@ exports.defineAutoTests = function () { }; writeFile(localFileName, fileContents, fileWin, fileFail); - - expect(lastProgressEvent).not.toBeNull('expected progress events'); - expect(lastProgressEvent.loaded).toBeGreaterThan(1, 'loaded'); - expect(lastProgressEvent.total).not.toBeLessThan(lastProgressEvent.loaded); - }); - it("filetransfer.spec.6 should get http status on basic auth failure", function (done) { - var uploadWin = createFail(done, "Upload success callback should not have been called"); - var fileFail = createFail(done, "Error writing file to be uploaded"); - var remoteFile = server + "/upload_basic_auth"; - localFileName = "upload_expect_fail.txt"; - var uploadFail = function (error) { - expect(error.http_status).toBe(401); - expect(error.http_status).not.toBe(404, "Ensure " + remoteFile + " is in the white list"); - done(); - }; - - var fileWin = function (fileEntry) { - var ft = new FileTransfer(); - - var options = new FileUploadOptions(); - options.fileKey = "file"; - options.fileName = fileEntry.name; - options.mimeType = "text/plain"; - - ft.upload(fileEntry.toURL(), remoteFile, uploadWin, uploadFail, options); - }; - - writeFile(localFileName, "this file should fail to upload", fileWin, fileFail); }); it("filetransfer.spec.21 should be stopped by abort() right away.", function (done) { var uploadWin = createFail(done, "Upload success callback should not have been called"); diff --git a/www/firefoxos/FileTransferProxy.js b/www/firefoxos/FileTransferProxy.js new file mode 100644 index 0000000..305ac58 --- /dev/null +++ b/www/firefoxos/FileTransferProxy.js @@ -0,0 +1,223 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ + +var cordova = require('cordova'), + FileTransferError = require('./FileTransferError'), + xhr = {}; + +function getParentPath(filePath) { + var pos = filePath.lastIndexOf('/'); + return filePath.substring(0, pos + 1); +} + +function getFileName(filePath) { + var pos = filePath.lastIndexOf('/'); + return filePath.substring(pos + 1); +} + +module.exports = { + abort: function (successCallback, errorCallback, args) { + var id = args[0]; + if (xhr[id]) { + xhr[id].abort(); + if (typeof(successCallback) === 'function') { + successCallback(); + } + } else if (typeof(errorCallback) === 'function') { + errorCallback(); + } + }, + + upload: function(successCallback, errorCallback, args) { + var filePath = args[0], + server = args[1], + fileKey = args[9], + fileName = args[3], + mimeType = args[4], + params = args[5], + /*trustAllHosts = args[6],*/ + /*chunkedMode = args[7],*/ + headers = args[8]; + + xhr[fileKey] = new XMLHttpRequest({mozSystem: true}); + xhr[fileKey].onabort = function() { + onFail(new FileTransferError(FileTransferError.ABORT_ERR, server, filePath, this.status, xhr[fileKey].response)); + }; + + window.resolveLocalFileSystemURL(filePath, function(entry) { + entry.file(function(file) { + var reader = new FileReader(); + + reader.onloadend = function() { + var blob = new Blob([this.result], {type: mimeType}); + var fd = new FormData(); + + fd.append(fileKey, blob, fileName); + + for (var prop in params) { + if (params.hasOwnProperty(prop)) { + fd.append(prop, params[prop]); + } + } + + xhr[fileKey].open("POST", server); + + xhr[fileKey].onload = function(evt) { + if (xhr[fileKey].status === 200) { + var result = new FileUploadResult(); + result.bytesSent = blob.size; + result.responseCode = xhr[fileKey].status; + result.response = xhr[fileKey].response; + delete xhr[fileKey]; + onSuccess(result); + } else if (xhr[fileKey].status === 404) { + onFail(new FileTransferError(FileTransferError.INVALID_URL_ERR, server, filePath, xhr[fileKey].status, xhr[fileKey].response)); + } else { + onFail(new FileTransferError(FileTransferError.CONNECTION_ERR, server, filePath, xhr[fileKey].status, xhr[fileKey].response)); + } + }; + + xhr[fileKey].ontimeout = function() { + onFail(new FileTransferError(FileTransferError.CONNECTION_ERR, server, filePath, xhr[fileKey].status, xhr[fileKey].response)); + }; + + xhr[fileKey].onerror = function() { + onFail(new FileTransferError(FileTransferError.CONNECTION_ERR, server, filePath, this.status, xhr[fileKey].response)); + }; + + for (var header in headers) { + if (headers.hasOwnProperty(header)) { + xhr[fileKey].setRequestHeader(header, headers[header]); + } + } + + xhr[fileKey].send(fd); + }; + + reader.readAsArrayBuffer(file); + + }, function() { + onFail(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR, server, filePath)); + }); + }, function() { + onFail(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR, server, filePath)); + }); + + function onSuccess(data) { + if (typeof(successCallback) === 'function') { + successCallback(data); + } + } + + function onFail(code) { + delete xhr[fileKey]; + if (typeof(errorCallback) === 'function') { + errorCallback(code); + } + } + }, + + download: function (successCallback, errorCallback, args) { + var source = args[0], + target = args[1], + id = args[3], + headers = args[4]; + + xhr[id] = new XMLHttpRequest({mozSystem: true}); + + xhr[id].onload = function () { + if (xhr[id].readyState === xhr[id].DONE) { + if (xhr[id].status === 200 && xhr[id].response) { + window.resolveLocalFileSystemURL(getParentPath(target), function (dir) { + dir.getFile(getFileName(target), {create: true}, writeFile, function (error) { + onFail(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR, source, target, xhr[id].status, xhr[id].response)); + }); + }, function () { + onFail(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR, source, target, xhr[id].status, xhr[id].response)); + }); + } else if (xhr[id].status === 404) { + onFail(new FileTransferError(FileTransferError.INVALID_URL_ERR, source, target, xhr[id].status, xhr[id].response)); + } else { + onFail(new FileTransferError(FileTransferError.CONNECTION_ERR, source, target, xhr[id].status, xhr[id].response)); + } + } + }; + + function writeFile(entry) { + entry.createWriter(function (fileWriter) { + fileWriter.onwriteend = function (evt) { + if (!evt.target.error) { + entry.filesystemName = entry.filesystem.name; + delete xhr[id]; + onSuccess(entry); + } else { + onFail(evt.target.error); + } + }; + fileWriter.onerror = function (evt) { + onFail(evt.target.error); + }; + fileWriter.write(new Blob([xhr[id].response])); + }, function (error) { + onFail(error); + }); + } + + xhr[id].onerror = function (e) { + onFail(new FileTransferError(FileTransferError.CONNECTION_ERR, source, target, xhr[id].status, xhr[id].response)); + }; + + xhr[id].onabort = function (e) { + onFail(new FileTransferError(FileTransferError.ABORT_ERR, source, target, xhr[id].status, xhr[id].response)); + }; + + xhr[id].open("GET", source, true); + + for (var header in headers) { + if (headers.hasOwnProperty(header)) { + xhr[id].setRequestHeader(header, headers[header]); + } + } + + xhr[id].responseType = "blob"; + + setTimeout(function () { + if (xhr[id]) { + xhr[id].send(); + } + }, 0); + + function onSuccess(entry) { + if (typeof(successCallback) === 'function') { + successCallback(entry); + } + } + + function onFail(error) { + delete xhr[id]; + if (typeof(errorCallback) === 'function') { + errorCallback(error); + } + } + } +}; + +require('cordova/exec/proxy').add('FileTransfer', module.exports);