From f6cf2e638404e5d189d2d2a7bda334a3732bd8e4 Mon Sep 17 00:00:00 2001 From: vkovtun <viktor.kovtun@id.ethz.ch> Date: Fri, 3 Feb 2023 14:59:33 +0100 Subject: [PATCH] SSDM-13253 Fixed ghe issue with not always correctly uploaded folders and files. --- .../public/resources/api/v3/openbis.js | 36 ++++++------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/openbis.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/openbis.js index 6f26a539f64..20e526d55ae 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/openbis.js +++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/openbis.js @@ -387,14 +387,10 @@ define([ 'jquery', 'util/Json', 'as/dto/datastore/search/DataStoreSearchCriteria this._uploadFileWorkspaceDSSFile = function(file, parentId) { var dfd = jquery.Deferred(); this._getDataStores().done(function(dataStores) { - var filename = encodeURIComponent(parentId + "/" + - (file.webkitRelativePath ? file.webkitRelativePath : file.name)); var sessionID = facade._private.sessionToken; - var fileSize = file.size; var chunkSize = 1048576; // 1 MiB var startByte = 0; - var iterator = streamFile(file, chunkSize); - uploadBlob(dataStores[0], iterator, sessionID, filename, startByte, chunkSize, fileSize) + uploadBlob(dataStores[0], parentId, sessionID, file, startByte, chunkSize) .done(function() { dfd.resolve(); }).fail(function(error) { @@ -406,10 +402,15 @@ define([ 'jquery', 'util/Json', 'as/dto/datastore/search/DataStoreSearchCriteria return dfd.promise(); } - function uploadBlob(dataStore, iterator, sessionID, filename, startByte, chunkSize, fileSize) { + function uploadBlob(dataStore, parentId, sessionID, file, startByte, chunkSize) { var dfd = jquery.Deferred(); - var blob = iterator.next(); - if (blob) { + var fileSize = file.size; + + if (startByte < fileSize) { + var blob = makeChunk(file, startByte, Math.min(startByte + chunkSize, fileSize)); + + var filename = encodeURIComponent(parentId + "/" + + (file.webkitRelativePath ? file.webkitRelativePath : file.name)); var parameters = "?sessionID=" + sessionID + "&filename=" + filename + "&id=1&startByte=" + startByte + "&endByte=" + (startByte + chunkSize) + "&size=" + fileSize + "&emptyFolder=false"; @@ -420,8 +421,7 @@ define([ 'jquery', 'util/Json', 'as/dto/datastore/search/DataStoreSearchCriteria }, body: blob }).then(function () { - uploadBlob(dataStore, iterator, sessionID, filename, startByte + chunkSize, chunkSize, - fileSize); + uploadBlob(dataStore, parentId, sessionID, file, startByte + chunkSize, chunkSize); dfd.resolve(); }).catch(function (error) { console.error("Error:", error); @@ -433,22 +433,6 @@ define([ 'jquery', 'util/Json', 'as/dto/datastore/search/DataStoreSearchCriteria return dfd.promise(); } - function streamFile(file, chunkSize) { - var start = 0; - var value; - return { - next() { - value = makeChunk(file, start, Math.min(start + chunkSize, file.size)); - if (value && value.size > 0) { - start += chunkSize; - return value; - } else { - return null; - } - } - } - } - function makeChunk(file, startByte, endByte) { var blob = undefined; if (file.slice) { -- GitLab