From 6dc72667fc2bbaf8b1bb585f12b64d0b2e1a2c9e Mon Sep 17 00:00:00 2001
From: Piotr Kosko
Date: Fri, 11 Dec 2020 14:21:18 +0100
Subject: [PATCH] [FileTransfer] Fixed file upload for server
[Issue] File was not properly sent to the server
On 6.0 implementation, problem was partially fixed, but new issues was
introduced - file.size was unknown when success callback was triggered.
[Verification] Described in JIRA task:
https://code.sec.samsung.net/jira/browse/XWALK-2197
TCT passrate 100%
Change-Id: Ic3716c1e2eaa9bc799120adb86aa71c4146064a1
---
.../tizen/FileTransfer.js | 32 +++++++++----------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/src/lib/plugins/cordova-plugin-file-transfer/tizen/FileTransfer.js b/src/lib/plugins/cordova-plugin-file-transfer/tizen/FileTransfer.js
index bcf20cf..f4342a4 100755
--- a/src/lib/plugins/cordova-plugin-file-transfer/tizen/FileTransfer.js
+++ b/src/lib/plugins/cordova-plugin-file-transfer/tizen/FileTransfer.js
@@ -110,22 +110,6 @@ exports = {
}
}
- xhr.onload = function(evt) {
-
- if (xhr.status === 200) {
- uploads[id] && delete uploads[id];
- successCallback({
- bytesSent: file.size,
- responseCode: xhr.status,
- response: xhr.response
- });
- } else if (xhr.status === 404) {
- fail(FileTransferError.INVALID_URL_ERR, this.status, this.response);
- } else {
- fail(FileTransferError.CONNECTION_ERR, this.status, this.response);
- }
- };
-
xhr.ontimeout = function(evt) {
fail(FileTransferError.CONNECTION_ERR, this.status, this.response);
};
@@ -164,6 +148,22 @@ exports = {
}
// sending already initialized request
+ // 'onload' needs to be defined here because it needs blobFile.size
+ xhr.onload = function(evt) {
+ // 2xx codes are valid
+ if (xhr.status >= 200 && xhr.status < 300) {
+ uploads[id] && delete uploads[id];
+ successCallback({
+ bytesSent: blobFile.size,
+ responseCode: xhr.status,
+ response: xhr.response
+ });
+ } else if (xhr.status === 404) {
+ fail(FileTransferError.INVALID_URL_ERR, this.status, this.response);
+ } else {
+ fail(FileTransferError.CONNECTION_ERR, this.status, this.response);
+ }
+ };
xhr.send(fd);
// Special case when transfer already aborted, but XHR isn't sent.
--
2.34.1