[FileTransfer] Fixing upload method for strict typing check 37/227637/4 accepted/tizen/unified/20200316.221003 submit/tizen/20200313.122957
authorPiotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/Samsung Electronics <p.kosko@samsung.com>
Fri, 13 Mar 2020 11:27:07 +0000 (12:27 +0100)
committerPiotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/Samsung Electronics <p.kosko@samsung.com>
Fri, 13 Mar 2020 12:27:34 +0000 (13:27 +0100)
[Bug] Because of strict type control in M76 Chromium update,
  object passed to FormData need to inherit from JS
  built-in type - Blob.

[Verification]
  tct-file-transfer-cordova-tests 100% (TM1 tizen-unified_20200312.1)

Change-Id: Ib0496113555bee8615e519802e3ce0a9d165b6fa

src/lib/plugins/cordova-plugin-file-transfer/tizen/FileTransfer.js

index e84fb2a..2042474 100755 (executable)
@@ -98,6 +98,7 @@ exports = {
 
     function successCB(entry) {
       if (entry.isFile) {
+        var fullPath = entry.toURL();
         entry.file(function(file) {
           function uploadFile(blobFile) {
             var fd = new FormData();
@@ -161,7 +162,18 @@ exports = {
             }
           }
 
-          uploadFile(file);
+          var fileHandle;
+          try {
+            fileHandle = tizen.filesystem.openFile(fullPath, 'r');
+            var fileBlob = fileHandle.readBlob();
+            uploadFile(fileBlob);
+          } catch (e) {
+            fail(FileTransferError.ABORT_ERR, 'Could not read file');
+          } finally {
+            if (fileHandle) {
+              fileHandle.close();
+            }
+          }
 
         }, function(error) {
           fail(FileTransferError.CONNECTION_ERR);