src/main/java/org/edgegallery/appstore/interfaces/apackage/facade/PackageServiceFacade.java
public ResponseEntity<InputStreamResource> downloadPackage(String appId, String packageId, boolean isDownloadImage,
        String token) throws IOException {
        Release release = appService.download(appId, packageId);
        InputStream ins;
        if (isDownloadImage) {
            String storageAddress = release.getPackageFile().getStorageAddress();
            String fileParent = storageAddress.substring(0, storageAddress.lastIndexOf(ZIP_POINT));
            appUtil.loadZipIntoPackage(storageAddress, token, fileParent);
            String fileZipName = new File(storageAddress).getParentFile().getCanonicalFile() + File.separator
                + TEMP_EXPIRE_PREFIX + release.getAppBasicInfo().getAppName();
            String fileAddress = appUtil.compressAndDeleteFile(fileParent, fileZipName, ZIP_EXTENSION);
            ins = fileService.get(fileAddress);
        } else {
            ins = fileService.get(release.getPackageFile());
        }
        String fileName = release.getAppBasicInfo().getAppName() + "_download" + ZIP_EXTENSION;
        String encodeFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.name());
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/octet-stream");
        headers.add("Content-Disposition", "attachment; filename=" + encodeFileName);
        return ResponseEntity.ok().headers(headers).body(new InputStreamResource(ins));
    }
/**
     * download package by package id.
     *
     * @param appId app id.
     * @param packageId package id.
     */
download package by package id.
@param appId app id.
@param packageId package id.
download package by package id . @param appId app id . @param packageId package id .
public ResponseEntity<InputStreamResource> downloadPackage(String appId, String packageId, boolean isDownloadImage,
        String token) throws IOException {
        Release release = appService.download(appId, packageId);
        InputStream ins;
        if (isDownloadImage) {
            String storageAddress = release.getPackageFile().getStorageAddress();
            String fileParent = storageAddress.substring(0, storageAddress.lastIndexOf(ZIP_POINT));
            appUtil.loadZipIntoPackage(storageAddress, token, fileParent);
            String fileZipName = new File(storageAddress).getParentFile().getCanonicalFile() + File.separator
                + TEMP_EXPIRE_PREFIX + release.getAppBasicInfo().getAppName();
            String fileAddress = appUtil.compressAndDeleteFile(fileParent, fileZipName, ZIP_EXTENSION);
            ins = fileService.get(fileAddress);
        } else {
            ins = fileService.get(release.getPackageFile());
        }
        String fileName = release.getAppBasicInfo().getAppName() + "_download" + ZIP_EXTENSION;
        String encodeFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.name());
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/octet-stream");
        headers.add("Content-Disposition", "attachment; filename=" + encodeFileName);
        return ResponseEntity.ok().headers(headers).body(new InputStreamResource(ins));
    }
public ResponseEntity < InputStreamResource > downloadPackage ( String appId , String packageId , boolean isDownloadImage , String token ) throws IOException { Release release = appService . download ( appId , packageId ) ; InputStream ins ; if ( isDownloadImage ) { String storageAddress = release . getPackageFile ( ) . getStorageAddress ( ) ; String fileParent = storageAddress . substring ( 0 , storageAddress . lastIndexOf ( ZIP_POINT ) ) ; appUtil . loadZipIntoPackage ( storageAddress , token , fileParent ) ; String fileZipName = new File ( storageAddress ) . getParentFile ( ) . getCanonicalFile ( ) + File . separator + TEMP_EXPIRE_PREFIX + release . getAppBasicInfo ( ) . getAppName ( ) ; String fileAddress = appUtil . compressAndDeleteFile ( fileParent , fileZipName , ZIP_EXTENSION ) ; ins = fileService . get ( fileAddress ) ; } else { ins = fileService . get ( release . getPackageFile ( ) ) ; } String fileName = release . getAppBasicInfo ( ) . getAppName ( ) + "_download" + ZIP_EXTENSION ; String encodeFileName = URLEncoder . encode ( fileName , StandardCharsets . UTF_8 . name ( ) ) ; HttpHeaders headers = new HttpHeaders ( ) ; headers . add ( "Content-Type" , "application/octet-stream" ) ; headers . add ( "Content-Disposition" , "attachment; filename=" + encodeFileName ) ; return ResponseEntity . ok ( ) . headers ( headers ) . body ( new InputStreamResource ( ins ) ) ; }
download package by package id.
download package by package id .