Skip to content

Commit

Permalink
Fix folder download (#3264)
Browse files Browse the repository at this point in the history
  • Loading branch information
cesnietor authored Mar 14, 2024
1 parent 78990e3 commit 6a38a09
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions web-app/src/screens/Console/Buckets/ListBuckets/Objects/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { BucketObjectItem } from "./ListObjects/types";
import { encodeURLString } from "../../../../../common/utils";
import { decodeURLString, encodeURLString } from "../../../../../common/utils";
import { removeTrace } from "../../../ObjectBrowser/transferManager";
import store from "../../../../../store";
import { ContentType, PermissionResource } from "api/consoleApi";
Expand Down Expand Up @@ -64,6 +64,11 @@ export const downloadSelectedAsZip = async (
);
}
};

const isFolder = (objectPath: string) => {
return decodeURLString(objectPath).endsWith("/");
};

export const download = (
bucketName: string,
objectPath: string,
Expand Down Expand Up @@ -116,7 +121,9 @@ export const download = (
req.responseType = "blob";
req.onreadystatechange = () => {
if (req.readyState === XMLHttpRequest.DONE) {
let completeDownload = req.response.size === fileSize;
// Ensure object was downloaded fully, if it's a folder we don't get the fileSize
let completeDownload =
isFolder(objectPath) || req.response.size === fileSize;

if (req.status === StatusCodes.OK && completeDownload) {
const rspHeader = req.getResponseHeader("Content-Disposition");
Expand Down

0 comments on commit 6a38a09

Please sign in to comment.