@@ -129,6 +129,8 @@ const (
129129 sbomScanTypeErrMsg = "The --sbom-only flag can only be used when the scan type is sca"
130130 BranchPrimaryPrefix = "--branch-primary="
131131 OverridePolicyManagement = "override-policy-management"
132+ maxSizeGB = 5 // 5 GB
133+ maxSizeBytes = maxSizeGB * 1024 * 1024 * 1024 // 5 GB in bytes
132134)
133135
134136var (
@@ -2082,7 +2084,26 @@ func uploadZip(uploadsWrapper wrappers.UploadsWrapper, zipFilePath string, unzip
20822084 var zipFilePathErr error
20832085 // Send a request to uploads service
20842086 var preSignedURL * string
2085- preSignedURL , zipFilePathErr = uploadsWrapper .UploadFile (zipFilePath , featureFlagsWrapper )
2087+
2088+ // calculate file size and compare with 5GB limit
2089+ fileInfo , err := os .Stat (zipFilePath )
2090+ if err != nil {
2091+ return "" , zipFilePath , errors .Wrapf (err , "Failed to stat %s" , zipFilePath )
2092+ }
2093+ logger .PrintIfVerbose (fmt .Sprintf ("Zip size before upload: %.2fMB\n " , float64 (fileInfo .Size ())/ mbBytes ))
2094+
2095+ // check for INCREASE_FILE_UPLOAD_LIMIT feature flag
2096+ flagResponse , _ := wrappers .GetSpecificFeatureFlag (featureFlagsWrapper , wrappers .IncreaseFileUploadLimit )
2097+
2098+ if flagResponse .Status && fileInfo .Size () > maxSizeBytes {
2099+ // File size >5GB, proceed with multipart upload
2100+ logger .PrintIfVerbose ("File size >5GB and INCREASE_FILE_UPLOAD_LIMIT flag is enabled,hence uploading file in multiple parts..." )
2101+ preSignedURL , zipFilePathErr = uploadsWrapper .UploadFileInMultipart (zipFilePath , featureFlagsWrapper )
2102+ } else {
2103+ // File size is within <=5GB, proceed with upload in single part
2104+ logger .PrintIfVerbose ("File size is within the limit and uploading file in a single part..." )
2105+ preSignedURL , zipFilePathErr = uploadsWrapper .UploadFile (zipFilePath , featureFlagsWrapper )
2106+ }
20862107 if zipFilePathErr != nil {
20872108 if unzip || ! userProvidedZip {
20882109 return "" , zipFilePath , errors .Wrapf (zipFilePathErr , "%s: Failed to upload sources file\n " , failedCreating )
0 commit comments