cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rakat...@apache.org
Subject svn commit: r1744142 [5/9] - in /cordova/site/public: ./ docs/en/6.x/ docs/en/6.x/config_ref/ docs/en/6.x/cordova/events/ docs/en/6.x/cordova/storage/ docs/en/6.x/guide/platforms/win8/ docs/en/6.x/plugin_ref/ docs/en/6.x/reference/cordova-cli/ docs/en/...
Date Mon, 16 May 2016 21:17:45 GMT
Modified: cordova/site/public/docs/en/6.x/reference/cordova-plugin-file-transfer/index.html
URL: http://svn.apache.org/viewvc/cordova/site/public/docs/en/6.x/reference/cordova-plugin-file-transfer/index.html?rev=1744142&r1=1744141&r2=1744142&view=diff
==============================================================================
--- cordova/site/public/docs/en/6.x/reference/cordova-plugin-file-transfer/index.html (original)
+++ cordova/site/public/docs/en/6.x/reference/cordova-plugin-file-transfer/index.html Mon May 16 21:17:45 2016
@@ -2687,15 +2687,15 @@
 <p>This plugin allows you to upload and download files.</p>
 
 <p>This plugin defines global <code>FileTransfer</code>, <code>FileUploadOptions</code> constructors. Although in the global scope, they are not available until after the <code>deviceready</code> event.</p>
-<div class="highlight"><pre><code class="language-" data-lang="">document.addEventListener("deviceready", onDeviceReady, false);
-function onDeviceReady() {
-    console.log(FileTransfer);
-}
+<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="nb">document</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="s2">"deviceready"</span><span class="p">,</span> <span class="nx">onDeviceReady</span><span class="p">,</span> <span class="kc">false</span><span class="p">);</span>
+<span class="kd">function</span> <span class="nx">onDeviceReady</span><span class="p">()</span> <span class="p">{</span>
+    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">FileTransfer</span><span class="p">);</span>
+<span class="p">}</span>
 </code></pre></div>
 <p>Report issues with this plugin on the <a href="https://issues.apache.org/jira/issues/?jql=project%20%3D%20CB%20AND%20status%20in%20%28Open%2C%20%22In%20Progress%22%2C%20Reopened%29%20AND%20resolution%20%3D%20Unresolved%20AND%20component%20%3D%20%22Plugin%20File%20Transfer%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC">Apache Cordova issue tracker</a></p>
 
 <h2>Installation</h2>
-<div class="highlight"><pre><code class="language-" data-lang="">cordova plugin add cordova-plugin-file-transfer
+<div class="highlight"><pre><code class="language-bash" data-lang="bash">cordova plugin add cordova-plugin-file-transfer
 </code></pre></div>
 <h2>Supported Platforms</h2>
 
@@ -2757,68 +2757,68 @@ multi-part POST or PUT request, and to d
 </ul>
 
 <h3>Example</h3>
-<div class="highlight"><pre><code class="language-" data-lang="">// !! Assumes variable fileURL contains a valid URL to a text file on the device,
-//    for example, cdvfile://localhost/persistent/path/to/file.txt
+<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="c1">// !! Assumes variable fileURL contains a valid URL to a text file on the device,</span>
+<span class="c1">//    for example, cdvfile://localhost/persistent/path/to/file.txt</span>
 
-var win = function (r) {
-    console.log("Code = " + r.responseCode);
-    console.log("Response = " + r.response);
-    console.log("Sent = " + r.bytesSent);
-}
-
-var fail = function (error) {
-    alert("An error has occurred: Code = " + error.code);
-    console.log("upload error source " + error.source);
-    console.log("upload error target " + error.target);
-}
-
-var options = new FileUploadOptions();
-options.fileKey = "file";
-options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1);
-options.mimeType = "text/plain";
-
-var params = {};
-params.value1 = "test";
-params.value2 = "param";
+<span class="kd">var</span> <span class="nx">win</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">r</span><span class="p">)</span> <span class="p">{</span>
+    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Code = "</span> <span class="o">+</span> <span class="nx">r</span><span class="p">.</span><span class="nx">responseCode</span><span class="p">);</span>
+    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Response = "</span> <span class="o">+</span> <span class="nx">r</span><span class="p">.</span><span class="nx">response</span><span class="p">);</span>
+    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Sent = "</span> <span class="o">+</span> <span class="nx">r</span><span class="p">.</span><span class="nx">bytesSent</span><span class="p">);</span>
+<span class="p">}</span>
+
+<span class="kd">var</span> <span class="nx">fail</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span>
+    <span class="nx">alert</span><span class="p">(</span><span class="s2">"An error has occurred: Code = "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">.</span><span class="nx">code</span><span class="p">);</span>
+    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"upload error source "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">.</span><span class="nx">source</span><span class="p">);</span>
+    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"upload error target "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">.</span><span class="nx">target</span><span class="p">);</span>
+<span class="p">}</span>
+
+<span class="kd">var</span> <span class="nx">options</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FileUploadOptions</span><span class="p">();</span>
+<span class="nx">options</span><span class="p">.</span><span class="nx">fileKey</span> <span class="o">=</span> <span class="s2">"file"</span><span class="p">;</span>
+<span class="nx">options</span><span class="p">.</span><span class="nx">fileName</span> <span class="o">=</span> <span class="nx">fileURL</span><span class="p">.</span><span class="nx">substr</span><span class="p">(</span><span class="nx">fileURL</span><span class="p">.</span><span class="nx">lastIndexOf</span><span class="p">(</span><span class="s1">'/'</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
+<span class="nx">options</span><span class="p">.</span><span class="nx">mimeType</span> <span class="o">=</span> <span class="s2">"text/plain"</span><span class="p">;</span>
+
+<span class="kd">var</span> <span class="nx">params</span> <span class="o">=</span> <span class="p">{};</span>
+<span class="nx">params</span><span class="p">.</span><span class="nx">value1</span> <span class="o">=</span> <span class="s2">"test"</span><span class="p">;</span>
+<span class="nx">params</span><span class="p">.</span><span class="nx">value2</span> <span class="o">=</span> <span class="s2">"param"</span><span class="p">;</span>
 
-options.params = params;
+<span class="nx">options</span><span class="p">.</span><span class="nx">params</span> <span class="o">=</span> <span class="nx">params</span><span class="p">;</span>
 
-var ft = new FileTransfer();
-ft.upload(fileURL, encodeURI("http://some.server.com/upload.php"), win, fail, options);
+<span class="kd">var</span> <span class="nx">ft</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FileTransfer</span><span class="p">();</span>
+<span class="nx">ft</span><span class="p">.</span><span class="nx">upload</span><span class="p">(</span><span class="nx">fileURL</span><span class="p">,</span> <span class="nb">encodeURI</span><span class="p">(</span><span class="s2">"http://some.server.com/upload.php"</span><span class="p">),</span> <span class="nx">win</span><span class="p">,</span> <span class="nx">fail</span><span class="p">,</span> <span class="nx">options</span><span class="p">);</span>
 </code></pre></div>
 <h3>Example with Upload Headers and Progress Events (Android and iOS only)</h3>
-<div class="highlight"><pre><code class="language-" data-lang="">function win(r) {
-    console.log("Code = " + r.responseCode);
-    console.log("Response = " + r.response);
-    console.log("Sent = " + r.bytesSent);
-}
-
-function fail(error) {
-    alert("An error has occurred: Code = " + error.code);
-    console.log("upload error source " + error.source);
-    console.log("upload error target " + error.target);
-}
-
-var uri = encodeURI("http://some.server.com/upload.php");
-
-var options = new FileUploadOptions();
-options.fileKey="file";
-options.fileName=fileURL.substr(fileURL.lastIndexOf('/')+1);
-options.mimeType="text/plain";
-
-var headers={'headerParam':'headerValue'};
-
-options.headers = headers;
-
-var ft = new FileTransfer();
-ft.onprogress = function(progressEvent) {
-    if (progressEvent.lengthComputable) {
-      loadingStatus.setPercentage(progressEvent.loaded / progressEvent.total);
-    } else {
-      loadingStatus.increment();
-    }
-};
-ft.upload(fileURL, uri, win, fail, options);
+<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">win</span><span class="p">(</span><span class="nx">r</span><span class="p">)</span> <span class="p">{</span>
+    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Code = "</span> <span class="o">+</span> <span class="nx">r</span><span class="p">.</span><span class="nx">responseCode</span><span class="p">);</span>
+    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Response = "</span> <span class="o">+</span> <span class="nx">r</span><span class="p">.</span><span class="nx">response</span><span class="p">);</span>
+    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Sent = "</span> <span class="o">+</span> <span class="nx">r</span><span class="p">.</span><span class="nx">bytesSent</span><span class="p">);</span>
+<span class="p">}</span>
+
+<span class="kd">function</span> <span class="nx">fail</span><span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span>
+    <span class="nx">alert</span><span class="p">(</span><span class="s2">"An error has occurred: Code = "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">.</span><span class="nx">code</span><span class="p">);</span>
+    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"upload error source "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">.</span><span class="nx">source</span><span class="p">);</span>
+    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"upload error target "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">.</span><span class="nx">target</span><span class="p">);</span>
+<span class="p">}</span>
+
+<span class="kd">var</span> <span class="nx">uri</span> <span class="o">=</span> <span class="nb">encodeURI</span><span class="p">(</span><span class="s2">"http://some.server.com/upload.php"</span><span class="p">);</span>
+
+<span class="kd">var</span> <span class="nx">options</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FileUploadOptions</span><span class="p">();</span>
+<span class="nx">options</span><span class="p">.</span><span class="nx">fileKey</span><span class="o">=</span><span class="s2">"file"</span><span class="p">;</span>
+<span class="nx">options</span><span class="p">.</span><span class="nx">fileName</span><span class="o">=</span><span class="nx">fileURL</span><span class="p">.</span><span class="nx">substr</span><span class="p">(</span><span class="nx">fileURL</span><span class="p">.</span><span class="nx">lastIndexOf</span><span class="p">(</span><span class="s1">'/'</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">);</span>
+<span class="nx">options</span><span class="p">.</span><span class="nx">mimeType</span><span class="o">=</span><span class="s2">"text/plain"</span><span class="p">;</span>
+
+<span class="kd">var</span> <span class="nx">headers</span><span class="o">=</span><span class="p">{</span><span class="s1">'headerParam'</span><span class="p">:</span><span class="s1">'headerValue'</span><span class="p">};</span>
+
+<span class="nx">options</span><span class="p">.</span><span class="nx">headers</span> <span class="o">=</span> <span class="nx">headers</span><span class="p">;</span>
+
+<span class="kd">var</span> <span class="nx">ft</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FileTransfer</span><span class="p">();</span>
+<span class="nx">ft</span><span class="p">.</span><span class="nx">onprogress</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">progressEvent</span><span class="p">)</span> <span class="p">{</span>
+    <span class="k">if</span> <span class="p">(</span><span class="nx">progressEvent</span><span class="p">.</span><span class="nx">lengthComputable</span><span class="p">)</span> <span class="p">{</span>
+        <span class="nx">loadingStatus</span><span class="p">.</span><span class="nx">setPercentage</span><span class="p">(</span><span class="nx">progressEvent</span><span class="p">.</span><span class="nx">loaded</span> <span class="o">/</span> <span class="nx">progressEvent</span><span class="p">.</span><span class="nx">total</span><span class="p">);</span>
+    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+        <span class="nx">loadingStatus</span><span class="p">.</span><span class="nx">increment</span><span class="p">();</span>
+    <span class="p">}</span>
+<span class="p">};</span>
+<span class="nx">ft</span><span class="p">.</span><span class="nx">upload</span><span class="p">(</span><span class="nx">fileURL</span><span class="p">,</span> <span class="nx">uri</span><span class="p">,</span> <span class="nx">win</span><span class="p">,</span> <span class="nx">fail</span><span class="p">,</span> <span class="nx">options</span><span class="p">);</span>
 </code></pre></div>
 <h2>FileUploadResult</h2>
 
@@ -2870,30 +2870,30 @@ ft.upload(fileURL, uri, win, fail, optio
 </ul>
 
 <h3>Example</h3>
-<div class="highlight"><pre><code class="language-" data-lang="">// !! Assumes variable fileURL contains a valid URL to a path on the device,
-//    for example, cdvfile://localhost/persistent/path/to/downloads/
+<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="c1">// !! Assumes variable fileURL contains a valid URL to a path on the device,</span>
+<span class="c1">//    for example, cdvfile://localhost/persistent/path/to/downloads/</span>
 
-var fileTransfer = new FileTransfer();
-var uri = encodeURI("http://some.server.com/download.php");
+<span class="kd">var</span> <span class="nx">fileTransfer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FileTransfer</span><span class="p">();</span>
+<span class="kd">var</span> <span class="nx">uri</span> <span class="o">=</span> <span class="nb">encodeURI</span><span class="p">(</span><span class="s2">"http://some.server.com/download.php"</span><span class="p">);</span>
 
-fileTransfer.download(
-    uri,
-    fileURL,
-    function(entry) {
-        console.log("download complete: " + entry.toURL());
-    },
-    function(error) {
-        console.log("download error source " + error.source);
-        console.log("download error target " + error.target);
-        console.log("upload error code" + error.code);
-    },
-    false,
-    {
-        headers: {
-            "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
-        }
-    }
-);
+<span class="nx">fileTransfer</span><span class="p">.</span><span class="nx">download</span><span class="p">(</span>
+    <span class="nx">uri</span><span class="p">,</span>
+    <span class="nx">fileURL</span><span class="p">,</span>
+    <span class="kd">function</span><span class="p">(</span><span class="nx">entry</span><span class="p">)</span> <span class="p">{</span>
+        <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"download complete: "</span> <span class="o">+</span> <span class="nx">entry</span><span class="p">.</span><span class="nx">toURL</span><span class="p">());</span>
+    <span class="p">},</span>
+    <span class="kd">function</span><span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span>
+        <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"download error source "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">.</span><span class="nx">source</span><span class="p">);</span>
+        <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"download error target "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">.</span><span class="nx">target</span><span class="p">);</span>
+        <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"upload error code"</span> <span class="o">+</span> <span class="nx">error</span><span class="p">.</span><span class="nx">code</span><span class="p">);</span>
+    <span class="p">},</span>
+    <span class="kc">false</span><span class="p">,</span>
+    <span class="p">{</span>
+        <span class="na">headers</span><span class="p">:</span> <span class="p">{</span>
+            <span class="s2">"Authorization"</span><span class="p">:</span> <span class="s2">"Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="</span>
+        <span class="p">}</span>
+    <span class="p">}</span>
+<span class="p">);</span>
 </code></pre></div>
 <h3>WP8 Quirks</h3>
 
@@ -2912,28 +2912,28 @@ fileTransfer.download(
 <p>Aborts an in-progress transfer. The onerror callback is passed a FileTransferError object which has an error code of <code>FileTransferError.ABORT_ERR</code>.</p>
 
 <h3>Example</h3>
-<div class="highlight"><pre><code class="language-" data-lang="">// !! Assumes variable fileURL contains a valid URL to a text file on the device,
-//    for example, cdvfile://localhost/persistent/path/to/file.txt
+<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="c1">// !! Assumes variable fileURL contains a valid URL to a text file on the device,</span>
+<span class="c1">//    for example, cdvfile://localhost/persistent/path/to/file.txt</span>
 
-var win = function(r) {
-    console.log("Should not be called.");
-}
-
-var fail = function(error) {
-    // error.code == FileTransferError.ABORT_ERR
-    alert("An error has occurred: Code = " + error.code);
-    console.log("upload error source " + error.source);
-    console.log("upload error target " + error.target);
-}
-
-var options = new FileUploadOptions();
-options.fileKey="file";
-options.fileName="myphoto.jpg";
-options.mimeType="image/jpeg";
-
-var ft = new FileTransfer();
-ft.upload(fileURL, encodeURI("http://some.server.com/upload.php"), win, fail, options);
-ft.abort();
+<span class="kd">var</span> <span class="nx">win</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">r</span><span class="p">)</span> <span class="p">{</span>
+    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Should not be called."</span><span class="p">);</span>
+<span class="p">}</span>
+
+<span class="kd">var</span> <span class="nx">fail</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span>
+    <span class="c1">// error.code == FileTransferError.ABORT_ERR</span>
+    <span class="nx">alert</span><span class="p">(</span><span class="s2">"An error has occurred: Code = "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">.</span><span class="nx">code</span><span class="p">);</span>
+    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"upload error source "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">.</span><span class="nx">source</span><span class="p">);</span>
+    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"upload error target "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">.</span><span class="nx">target</span><span class="p">);</span>
+<span class="p">}</span>
+
+<span class="kd">var</span> <span class="nx">options</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FileUploadOptions</span><span class="p">();</span>
+<span class="nx">options</span><span class="p">.</span><span class="nx">fileKey</span><span class="o">=</span><span class="s2">"file"</span><span class="p">;</span>
+<span class="nx">options</span><span class="p">.</span><span class="nx">fileName</span><span class="o">=</span><span class="s2">"myphoto.jpg"</span><span class="p">;</span>
+<span class="nx">options</span><span class="p">.</span><span class="nx">mimeType</span><span class="o">=</span><span class="s2">"image/jpeg"</span><span class="p">;</span>
+
+<span class="kd">var</span> <span class="nx">ft</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FileTransfer</span><span class="p">();</span>
+<span class="nx">ft</span><span class="p">.</span><span class="nx">upload</span><span class="p">(</span><span class="nx">fileURL</span><span class="p">,</span> <span class="nb">encodeURI</span><span class="p">(</span><span class="s2">"http://some.server.com/upload.php"</span><span class="p">),</span> <span class="nx">win</span><span class="p">,</span> <span class="nx">fail</span><span class="p">,</span> <span class="nx">options</span><span class="p">);</span>
+<span class="nx">ft</span><span class="p">.</span><span class="nx">abort</span><span class="p">();</span>
 </code></pre></div>
 <h2>FileTransferError</h2>
 
@@ -2983,6 +2983,229 @@ ft.abort();
 </code></pre></div>
 <p>which can be used in place of the absolute file path in both <code>download()</code> and <code>upload()</code> methods.</p>
 
+<h2>Sample: Download and Upload Files <a name="sample"></a></h2>
+
+<p>Use the File-Transfer plugin to upload and download files. In these examples, we demonstrate several tasks like:</p>
+
+<ul>
+<li><a href="#binaryFile">Downloading a binary file to the application cache</a></li>
+<li><a href="#uploadFile">Uploading a file created in your application&#39;s root</a></li>
+<li><a href="#downloadFile">Downloading the uploaded file</a></li>
+</ul>
+
+<h2>Download a Binary File to the application cache <a name="binaryFile"></a></h2>
+
+<p>Use the File plugin with the File-Transfer plugin to provide a target for the files that you download (the target must be a FileEntry object). Before you download the file, create a DirectoryEntry object by using <code>resolveLocalFileSystemURL</code> and calling <code>fs.root</code> in the success callback. Use the <code>getFile</code> method of DirectoryEntry to create the target file.</p>
+<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="nb">window</span><span class="p">.</span><span class="nx">requestFileSystem</span><span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">TEMPORARY</span><span class="p">,</span> <span class="mi">5</span> <span class="o">*</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">1024</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">fs</span><span class="p">)</span> <span class="p">{</span>
+
+    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">'file system open: '</span> <span class="o">+</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">name</span><span class="p">);</span>
+
+    <span class="c1">// Make sure you add the domain name to the Content-Security-Policy &lt;meta&gt; element.</span>
+    <span class="kd">var</span> <span class="nx">url</span> <span class="o">=</span> <span class="s1">'http://cordova.apache.org/static/img/cordova_bot.png'</span><span class="p">;</span>
+    <span class="c1">// Parameters passed to getFile create a new file or return the file if it already exists.</span>
+    <span class="nx">fs</span><span class="p">.</span><span class="nx">root</span><span class="p">.</span><span class="nx">getFile</span><span class="p">(</span><span class="s1">'downloaded-image.png'</span><span class="p">,</span> <span class="p">{</span> <span class="na">create</span><span class="p">:</span> <span class="kc">true</span><span class="p">,</span> <span class="na">exclusive</span><span class="p">:</span> <span class="kc">false</span> <span class="p">},</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">fileEntry</span><span class="p">)</span> <span class="p">{</span>
+        <span class="nx">download</span><span class="p">(</span><span class="nx">fileEntry</span><span class="p">,</span> <span class="nx">url</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
+
+    <span class="p">},</span> <span class="nx">onErrorCreateFile</span><span class="p">);</span>
+
+<span class="p">},</span> <span class="nx">onErrorLoadFs</span><span class="p">);</span>
+</code></pre></div>
+<blockquote>
+<p><em>Note</em> For persistent storage, pass LocalFileSystem.PERSISTENT to requestFileSystem.</p>
+</blockquote>
+
+<p>When you have the FileEntry object, download the file using the <code>download</code> method of the FileTransfer object. The 3rd argument to the <code>download</code> function of FileTransfer is the success callback, which you can use to call the app&#39;s <code>readBinaryFile</code> function. In this code example, the <code>entry</code> variable is a new FileEntry object that receives the result of the download operation.</p>
+<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">download</span><span class="p">(</span><span class="nx">fileEntry</span><span class="p">,</span> <span class="nx">uri</span><span class="p">,</span> <span class="nx">readBinaryData</span><span class="p">)</span> <span class="p">{</span>
+
+    <span class="kd">var</span> <span class="nx">fileTransfer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FileTransfer</span><span class="p">();</span>
+    <span class="kd">var</span> <span class="nx">fileURL</span> <span class="o">=</span> <span class="nx">fileEntry</span><span class="p">.</span><span class="nx">toURL</span><span class="p">();</span>
+
+    <span class="nx">fileTransfer</span><span class="p">.</span><span class="nx">download</span><span class="p">(</span>
+        <span class="nx">uri</span><span class="p">,</span>
+        <span class="nx">fileURL</span><span class="p">,</span>
+        <span class="kd">function</span> <span class="p">(</span><span class="nx">entry</span><span class="p">)</span> <span class="p">{</span>
+            <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Successful download..."</span><span class="p">);</span>
+            <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"download complete: "</span> <span class="o">+</span> <span class="nx">entry</span><span class="p">.</span><span class="nx">toURL</span><span class="p">());</span>
+            <span class="k">if</span> <span class="p">(</span><span class="nx">readBinaryData</span><span class="p">)</span> <span class="p">{</span>
+              <span class="c1">// Read the file...</span>
+              <span class="nx">readBinaryFile</span><span class="p">(</span><span class="nx">entry</span><span class="p">);</span>
+            <span class="p">}</span>
+            <span class="k">else</span> <span class="p">{</span>
+              <span class="c1">// Or just display it.</span>
+              <span class="nx">displayImageByFileURL</span><span class="p">(</span><span class="nx">entry</span><span class="p">);</span>
+            <span class="p">}</span>
+        <span class="p">},</span>
+        <span class="kd">function</span> <span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span>
+            <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"download error source "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">.</span><span class="nx">source</span><span class="p">);</span>
+            <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"download error target "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">.</span><span class="nx">target</span><span class="p">);</span>
+            <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"upload error code"</span> <span class="o">+</span> <span class="nx">error</span><span class="p">.</span><span class="nx">code</span><span class="p">);</span>
+        <span class="p">},</span>
+        <span class="kc">null</span><span class="p">,</span> <span class="c1">// or, pass false</span>
+        <span class="p">{</span>
+            <span class="c1">//headers: {</span>
+            <span class="c1">//    "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="</span>
+            <span class="c1">//}</span>
+        <span class="p">}</span>
+    <span class="p">);</span>
+<span class="p">}</span>
+</code></pre></div>
+<p>If you just need to display the image, take the FileEntry to call its toURL() function.</p>
+<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">displayImageByFileURL</span><span class="p">(</span><span class="nx">fileEntry</span><span class="p">)</span> <span class="p">{</span>
+    <span class="kd">var</span> <span class="nx">elem</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="s1">'imageFile'</span><span class="p">);</span>
+    <span class="nx">elem</span><span class="p">.</span><span class="nx">src</span> <span class="o">=</span> <span class="nx">fileEntry</span><span class="p">.</span><span class="nx">toURL</span><span class="p">();</span>
+<span class="p">}</span>
+</code></pre></div>
+<p>Depending on your app requirements, you may want to read the file. To support operations with binary files, FileReader supports two methods, <code>readAsBinaryString</code> and <code>readAsArrayBuffer</code>. In this example, use <code>readAsArrayBuffer</code> and pass the FileEntry object to the method. Once you read the file successfully, construct a Blob object using the result of the read.</p>
+<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">readBinaryFile</span><span class="p">(</span><span class="nx">fileEntry</span><span class="p">)</span> <span class="p">{</span>
+    <span class="nx">fileEntry</span><span class="p">.</span><span class="nx">file</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">file</span><span class="p">)</span> <span class="p">{</span>
+        <span class="kd">var</span> <span class="nx">reader</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FileReader</span><span class="p">();</span>
+
+        <span class="nx">reader</span><span class="p">.</span><span class="nx">onloadend</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
+
+            <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Successful file read: "</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">result</span><span class="p">);</span>
+            <span class="c1">// displayFileData(fileEntry.fullPath + ": " + this.result);</span>
+
+            <span class="kd">var</span> <span class="nx">blob</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Blob</span><span class="p">([</span><span class="k">new</span> <span class="nx">Uint8Array</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">result</span><span class="p">)],</span> <span class="p">{</span> <span class="na">type</span><span class="p">:</span> <span class="s2">"image/png"</span> <span class="p">});</span>
+            <span class="nx">displayImage</span><span class="p">(</span><span class="nx">blob</span><span class="p">);</span>
+        <span class="p">};</span>
+
+        <span class="nx">reader</span><span class="p">.</span><span class="nx">readAsArrayBuffer</span><span class="p">(</span><span class="nx">file</span><span class="p">);</span>
+
+    <span class="p">},</span> <span class="nx">onErrorReadFile</span><span class="p">);</span>
+<span class="p">}</span>
+</code></pre></div>
+<p>Once you read the file successfully, you can create a DOM URL string using <code>createObjectURL</code>, and then display the image.</p>
+<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">displayImage</span><span class="p">(</span><span class="nx">blob</span><span class="p">)</span> <span class="p">{</span>
+
+    <span class="c1">// Note: Use window.URL.revokeObjectURL when finished with image.</span>
+    <span class="kd">var</span> <span class="nx">objURL</span> <span class="o">=</span> <span class="nb">window</span><span class="p">.</span><span class="nx">URL</span><span class="p">.</span><span class="nx">createObjectURL</span><span class="p">(</span><span class="nx">blob</span><span class="p">);</span>
+
+    <span class="c1">// Displays image if result is a valid DOM string for an image.</span>
+    <span class="kd">var</span> <span class="nx">elem</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="s1">'imageFile'</span><span class="p">);</span>
+    <span class="nx">elem</span><span class="p">.</span><span class="nx">src</span> <span class="o">=</span> <span class="nx">objURL</span><span class="p">;</span>
+<span class="p">}</span>
+</code></pre></div>
+<p>As you saw previously, you can call FileEntry.toURL() instead to just display the downloaded image (skip the file read).</p>
+
+<h2>Upload a File <a name="uploadFile"></a>
+<p>When you upload a File using the File-Transfer plugin, use the File plugin to provide files for upload (again, they must be FileEntry objects). Before you can upload anything, create a file for upload using the <code>getFile</code> method of DirectoryEntry. In this example, create the file in the application&#39;s cache (fs.root). Then call the app&#39;s writeFile function so you have some content to upload.</p>
+<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">onUploadFile</span><span class="p">()</span> <span class="p">{</span>
+    <span class="nb">window</span><span class="p">.</span><span class="nx">requestFileSystem</span><span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">TEMPORARY</span><span class="p">,</span> <span class="mi">5</span> <span class="o">*</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">1024</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">fs</span><span class="p">)</span> <span class="p">{</span>
+
+        <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">'file system open: '</span> <span class="o">+</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">name</span><span class="p">);</span>
+        <span class="kd">var</span> <span class="nx">fileName</span> <span class="o">=</span> <span class="s2">"uploadSource.txt"</span><span class="p">;</span>
+        <span class="kd">var</span> <span class="nx">dirEntry</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">root</span><span class="p">;</span>
+        <span class="nx">dirEntry</span><span class="p">.</span><span class="nx">getFile</span><span class="p">(</span><span class="nx">fileName</span><span class="p">,</span> <span class="p">{</span> <span class="na">create</span><span class="p">:</span> <span class="kc">true</span><span class="p">,</span> <span class="na">exclusive</span><span class="p">:</span> <span class="kc">false</span> <span class="p">},</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">fileEntry</span><span class="p">)</span> <span class="p">{</span>
+
+            <span class="c1">// Write something to the file before uploading it.</span>
+            <span class="nx">writeFile</span><span class="p">(</span><span class="nx">fileEntry</span><span class="p">);</span>
+
+        <span class="p">},</span> <span class="nx">onErrorCreateFile</span><span class="p">);</span>
+
+    <span class="p">},</span> <span class="nx">onErrorLoadFs</span><span class="p">);</span>
+<span class="p">}</span>
+</code></pre></div>
+<p>In this example, create some simple content, and then call the app&#39;s upload function.</p>
+<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">writeFile</span><span class="p">(</span><span class="nx">fileEntry</span><span class="p">,</span> <span class="nx">dataObj</span><span class="p">)</span> <span class="p">{</span>
+    <span class="c1">// Create a FileWriter object for our FileEntry (log.txt).</span>
+    <span class="nx">fileEntry</span><span class="p">.</span><span class="nx">createWriter</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">fileWriter</span><span class="p">)</span> <span class="p">{</span>
+
+        <span class="nx">fileWriter</span><span class="p">.</span><span class="nx">onwriteend</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+            <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Successful file write..."</span><span class="p">);</span>
+            <span class="nx">upload</span><span class="p">(</span><span class="nx">fileEntry</span><span class="p">);</span>
+        <span class="p">};</span>
+
+        <span class="nx">fileWriter</span><span class="p">.</span><span class="nx">onerror</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
+            <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Failed file write: "</span> <span class="o">+</span> <span class="nx">e</span><span class="p">.</span><span class="nx">toString</span><span class="p">());</span>
+        <span class="p">};</span>
+
+        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">dataObj</span><span class="p">)</span> <span class="p">{</span>
+          <span class="nx">dataObj</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Blob</span><span class="p">([</span><span class="s1">'file data to upload'</span><span class="p">],</span> <span class="p">{</span> <span class="na">type</span><span class="p">:</span> <span class="s1">'text/plain'</span> <span class="p">});</span>
+        <span class="p">}</span>
+
+        <span class="nx">fileWriter</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="nx">dataObj</span><span class="p">);</span>
+    <span class="p">});</span>
+<span class="p">}</span>
+</code></pre></div>
+<p>Forward the FileEntry object to the upload function. To perform the actual upload, use the upload function of the FileTransfer object.</p>
+<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">upload</span><span class="p">(</span><span class="nx">fileEntry</span><span class="p">)</span> <span class="p">{</span>
+    <span class="c1">// !! Assumes variable fileURL contains a valid URL to a text file on the device,</span>
+    <span class="kd">var</span> <span class="nx">fileURL</span> <span class="o">=</span> <span class="nx">fileEntry</span><span class="p">.</span><span class="nx">toURL</span><span class="p">();</span>
+
+    <span class="kd">var</span> <span class="nx">success</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">r</span><span class="p">)</span> <span class="p">{</span>
+        <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Successful upload..."</span><span class="p">);</span>
+        <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Code = "</span> <span class="o">+</span> <span class="nx">r</span><span class="p">.</span><span class="nx">responseCode</span><span class="p">);</span>
+        <span class="nx">displayFileData</span><span class="p">(</span><span class="nx">fileEntry</span><span class="p">.</span><span class="nx">fullPath</span> <span class="o">+</span> <span class="s2">" (content uploaded to server)"</span><span class="p">);</span>
+    <span class="p">}</span>
+
+    <span class="kd">var</span> <span class="nx">fail</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span>
+        <span class="nx">alert</span><span class="p">(</span><span class="s2">"An error has occurred: Code = "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">.</span><span class="nx">code</span><span class="p">);</span>
+    <span class="p">}</span>
+
+    <span class="kd">var</span> <span class="nx">options</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FileUploadOptions</span><span class="p">();</span>
+    <span class="nx">options</span><span class="p">.</span><span class="nx">fileKey</span> <span class="o">=</span> <span class="s2">"file"</span><span class="p">;</span>
+    <span class="nx">options</span><span class="p">.</span><span class="nx">fileName</span> <span class="o">=</span> <span class="nx">fileURL</span><span class="p">.</span><span class="nx">substr</span><span class="p">(</span><span class="nx">fileURL</span><span class="p">.</span><span class="nx">lastIndexOf</span><span class="p">(</span><span class="s1">'/'</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
+    <span class="nx">options</span><span class="p">.</span><span class="nx">mimeType</span> <span class="o">=</span> <span class="s2">"text/plain"</span><span class="p">;</span>
+
+    <span class="kd">var</span> <span class="nx">params</span> <span class="o">=</span> <span class="p">{};</span>
+    <span class="nx">params</span><span class="p">.</span><span class="nx">value1</span> <span class="o">=</span> <span class="s2">"test"</span><span class="p">;</span>
+    <span class="nx">params</span><span class="p">.</span><span class="nx">value2</span> <span class="o">=</span> <span class="s2">"param"</span><span class="p">;</span>
+
+    <span class="nx">options</span><span class="p">.</span><span class="nx">params</span> <span class="o">=</span> <span class="nx">params</span><span class="p">;</span>
+
+    <span class="kd">var</span> <span class="nx">ft</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FileTransfer</span><span class="p">();</span>
+    <span class="c1">// SERVER must be a URL that can handle the request, like</span>
+    <span class="c1">// http://some.server.com/upload.php</span>
+    <span class="nx">ft</span><span class="p">.</span><span class="nx">upload</span><span class="p">(</span><span class="nx">fileURL</span><span class="p">,</span> <span class="nb">encodeURI</span><span class="p">(</span><span class="nx">SERVER</span><span class="p">),</span> <span class="nx">success</span><span class="p">,</span> <span class="nx">fail</span><span class="p">,</span> <span class="nx">options</span><span class="p">);</span>
+<span class="p">};</span>
+</code></pre></div>
+<h2>Download the uploaded file <a name="downloadFile"></a></h2>
+
+<p>To download the image you just uploaded, you will need a valid URL that can handle the request, for example, http://some.server.com/download.php. Again, the success handler for the FileTransfer.download method receives a FileEntry object. The main difference here from previous examples is that we call FileReader.readAsText to read the result of the download operation, because we uploaded a file with text content.</p>
+<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">download</span><span class="p">(</span><span class="nx">fileEntry</span><span class="p">,</span> <span class="nx">uri</span><span class="p">)</span> <span class="p">{</span>
+
+    <span class="kd">var</span> <span class="nx">fileTransfer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FileTransfer</span><span class="p">();</span>
+    <span class="kd">var</span> <span class="nx">fileURL</span> <span class="o">=</span> <span class="nx">fileEntry</span><span class="p">.</span><span class="nx">toURL</span><span class="p">();</span>
+
+    <span class="nx">fileTransfer</span><span class="p">.</span><span class="nx">download</span><span class="p">(</span>
+        <span class="nx">uri</span><span class="p">,</span>
+        <span class="nx">fileURL</span><span class="p">,</span>
+        <span class="kd">function</span> <span class="p">(</span><span class="nx">entry</span><span class="p">)</span> <span class="p">{</span>
+            <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Successful download..."</span><span class="p">);</span>
+            <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"download complete: "</span> <span class="o">+</span> <span class="nx">entry</span><span class="p">.</span><span class="nx">toURL</span><span class="p">());</span>
+            <span class="nx">readFile</span><span class="p">(</span><span class="nx">entry</span><span class="p">);</span>
+        <span class="p">},</span>
+        <span class="kd">function</span> <span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span>
+            <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"download error source "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">.</span><span class="nx">source</span><span class="p">);</span>
+            <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"download error target "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">.</span><span class="nx">target</span><span class="p">);</span>
+            <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"upload error code"</span> <span class="o">+</span> <span class="nx">error</span><span class="p">.</span><span class="nx">code</span><span class="p">);</span>
+        <span class="p">},</span>
+        <span class="kc">null</span><span class="p">,</span> <span class="c1">// or, pass false</span>
+        <span class="p">{</span>
+            <span class="c1">//headers: {</span>
+            <span class="c1">//    "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="</span>
+            <span class="c1">//}</span>
+        <span class="p">}</span>
+    <span class="p">);</span>
+<span class="p">}</span>
+</code></pre></div>
+<p>In the readFile function, call the <code>readAsText</code> method of the FileReader object.</p>
+<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">readFile</span><span class="p">(</span><span class="nx">fileEntry</span><span class="p">)</span> <span class="p">{</span>
+    <span class="nx">fileEntry</span><span class="p">.</span><span class="nx">file</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">file</span><span class="p">)</span> <span class="p">{</span>
+        <span class="kd">var</span> <span class="nx">reader</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FileReader</span><span class="p">();</span>
+
+        <span class="nx">reader</span><span class="p">.</span><span class="nx">onloadend</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+
+            <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Successful file read: "</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">result</span><span class="p">);</span>
+            <span class="c1">// displayFileData(fileEntry.fullPath + ": " + this.result);</span>
+
+        <span class="p">};</span>
+
+        <span class="nx">reader</span><span class="p">.</span><span class="nx">readAsText</span><span class="p">(</span><span class="nx">file</span><span class="p">);</span>
+
+    <span class="p">},</span> <span class="nx">onErrorReadFile</span><span class="p">);</span>
+<span class="p">}</span>
+</code></pre></div>
 
                 </div>
             </div>



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message