From: Piotr Kosko
Date: Fri, 11 Dec 2020 13:21:18 +0000 (+0100)
Subject: [FileTransfer] Fixed file upload for server
X-Git-Tag: submit/tizen/20210611.071245~1
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6dc72667fc2bbaf8b1bb585f12b64d0b2e1a2c9e;p=platform%2Fcore%2Fapi%2Fcordova-plugins.git
[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
---
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.