download 相关问题

从远程系统接收数据到本地系统,或启动此类数据传输。

在表格 Angular 8 中添加链接

我有一个包含一些列的表格,并且有一个可以单击和下载的“文档”列。 我怎样才能只将文档名称设为链接? 超文本标记语言 我有一个包含一些列的表格,还有一个可以单击和下载的“文档”列。 我怎样才能只将文档名称设为链接? HTML <p-table #dt3 [columns]="colsPermessi" [value]="permessi" [paginator]="true" [scrollable]="false" [rows]="10" [autoLayout]="true"> <ng-template pTemplate="header" let-columns> <tr> <th *ngFor="let col of columns" pResizableColumn>{{col.header}} </th> <th>Azioni</th> <th>Permessi</th> </tr> </ng-template> <ng-template pTemplate="body" let-rowData let-columns="columns"> <tr [pSelectableRow]="rowData"> <td *ngFor="let col of colsPermessi"> {{rowData[col.field]}} </td> </tr> </ng-template> 因此,我希望“文档”列可单击,单击时它会调用“downloadFile ()”函数。 我该怎么做? 这可以使用 *ngIf 来分隔你的案例来完成。对于 documento 列,使用 ngIf 插入超链接标记。对于其他所有内容,只需插入文本即可。请参阅下面的示例: <ng-template pTemplate="body" let-rowData let-columns="columns"> <tr [pSelectableRow]="rowData"> <td *ngFor="let col of colsPermessi"> <span *ngIf="col.header == 'Documento'><a [href]="col.url">{{rowData[col.field]}}</a></span> <span *ngIf="col.header != 'Documento'>{{rowData[col.field]}}</span> </td> </tr> </ng-template> 我可以看到/a标记,但我看不到标记

回答 2 投票 0

PHP 下载量为 0 字节

我的 ZIP 文件位于根目录上一级的目录中(以防止热链接等...)。这是代码: 我的 ZIP 文件位于根目录上一级的目录中(以防止热链接等...)。这是代码: <?php $filename = $_GET['id']; if(!$filename){ header("Location: index.html"); } else { function send_download($filename){ $file_path = '../../../../downloads/' . $filename . '.zip'; $file_size=@filesize($file_path); header("Content-Type: application/x-zip-compressed"); header("Content-disposition: attachment; filename=$filename"); header("Content-Length: $file_size"); readfile($file_path); exit; } send_download($filename); } ?> 所有 ZIP 文件都很好,但在“a”标签上使用此方法会导致下载的文件大小为 0 字节! :( 有什么想法吗? 非常感谢! 您可以尝试将 Content-type 更改为以下内容: Content-type: application/x-zip; 在此之前,请检查该文件是否存在。 <?php $filename = $_GET['id']; if(!$filename){ header("Location: index.html"); } else{ function send_download($filename){ $file_path = '../../../../downloads/' . $filename . '.zip'; if (file_exists($file_path)) { $file_size=@filesize($file_path); header("Content-Type: application/x-zip-compressed"); header("Content-disposition: attachment; filename=$filename"); header("Content-Length: $file_size"); readfile($file_path); exit; } send_download($filename); } else die("Error 404!"); } ?> header("位置:http://www.fqdn.tld/file.ext"); 基于 _GET["id"] > 0 并且不为 null,您创建了一个随后直接使用的函数,因此您只是添加了更多行代码,但没有任何必要的目的。 我看到您添加了“@”符号,正如人们之前评论的那样,但是,您开始解决此问题的唯一方法是: 删除@符号,因为你永远不应该使用它,这是非常糟糕的做法,你应该照顾代码中的所有异常,这才能成为一个真正优秀的程序员。 (PHP 脚本) 错误报告(E_ALL); 将点 b) 放在它自己的线上,但位于 之后 你的代码很好,你遇到的问题是权限,确保apache可以访问你的“文件”存储库,事实上你能够检查文件是否存在,这表明有轻微的权限并且文件存在,这一点是0返回字节表明读取权限在 Apache 级别被拒绝。 是的,经过一番谷歌搜索和一些心血、汗水和泪水,我终于找到了解决方案! <?php $filename = $_GET['id']; header('Content-type: application/zip'); header("Content-Disposition: attachment; filename=" . $filename); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); readfile('../../downloads/' . $filename . ".zip"); exit; ?> 非常感谢所有对此有所了解的人! 这是带有文件大小的代码: <?php $filename = $_GET['id']; $file = "../../downloads/" . $filename . ".zip"; header('Content-type: application/zip'); header("Content-Disposition: attachment; filename=" . $file); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-length: " . filesize($file)); readfile($file); //echo filesize($file); exit; ?> 只有一个错误,我们都在下面进行检查。 readfile($file); //$file 应该是相对的而不是绝对的。就是这样。 谢谢, 阿尼鲁德·苏德。 我知道这是一个非常老的问题,尽管我刚刚为自己解决了这个问题。就我而言,它是 Content-Length 标头,我有: header ('Content-Length: "'.$fileSize.'"'); 更改为: header ('Content-Length: '.$fileSize); 为我解决了这个问题,PHP 试图解释 " 但只用整数就可以了。

回答 6 投票 0

内存和硬盘中的 Zip 不同,导致下载后 Zip 损坏

大家好我想实现一个zip下载。我有一个网络应用程序,用户可以单击按钮: 大家好我想实现一个zip下载。我有一个网络应用程序,用户可以单击按钮: <template> <button name="exportButton" id="exportButton" @click="convertConfigurationToZip" :class="['button']">{{ exportConfig }} </button> </template> methods: { async convertConfigurationToZip() { // Stores the current config in "store.config" RestResource.convertConfigurationToZip(); const configData = store.config; await new Promise((resolve) => setTimeout(resolve, 2000)); // A Blob represents raw binary data const blob = new Blob([configData], {type: 'application/zip'}); // Use file-saver to trigger the download saveAs(blob, 'ProCAKE_Configuration') RestResource中调用的函数如下: convertConfigurationToZip: () => { axios .get("http://localhost:8080/api/conversion/convertConfigurationToZip/") .then((response: any) => { console.log(response.data); store.config = response.data; }) .catch((error: any) => { console.log(error); }) } 被调用的控制器如下所示: package controller; import io.swagger.annotations.*; import jakarta.annotation.Resource; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.container.AsyncResponse; import jakarta.ws.rs.container.Suspended; import jakarta.ws.rs.core.Response; import services.ConversionService; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; // This Controller should be used for creating zip files that contains the ProCake-Configuration @Api(tags = "Conversion Controller", authorizations = { @Authorization(value = "basicAuth") }) @Path("/conversion") public class ConversionController { @Resource ExecutorService executorService; @ApiOperation(value = "Convert Config into Zip") @ApiResponses({ @ApiResponse(code = 200, message = "Config as Zip"), @ApiResponse(code = 503, message = "ProCAKE not started/configured properly") }) @GET @Path("/convertConfigurationToZip") public void convertConfigurationToZip(@Suspended final AsyncResponse response) { executorService = Executors.newSingleThreadExecutor(); executorService.submit(() -> { try { response.resume(Response.status(200).entity(new ConversionService().convertConfigurationToZip()).build()); } catch (Exception e) { response.resume(e); } executorService.shutdown(); }); } } 处理 Zip 文件的服务如下所示: package services; import de.uni_trier.wi2.procake.data.model.Model; import de.uni_trier.wi2.procake.data.model.ModelFactory; import de.uni_trier.wi2.procake.similarity.SimilarityModel; import de.uni_trier.wi2.procake.similarity.SimilarityModelFactory; import de.uni_trier.wi2.procake.utils.io.IOUtil; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; import org.apache.commons.io.IOUtils; import org.apache.jena.sparql.exec.RowSet; import java.io.*; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.zip.ZipInputStream; public class ConversionService { public byte[] convertConfigurationToZip() throws IOException { try { // Create Zip on Harddrive List<File> listOfFiles = new ArrayList<File>(); File hello = new File("pathToFile"); File world = new File("pathToFile"); listOfFiles.add(hello); listOfFiles.add(world); IOUtil.createZipFile("pathToZip", listOfFiles); // --------------------- // Create Zip File in Memory ByteArrayOutputStream baos = IOUtil.createZipFileInMemory(listOfFiles); ; // --------------------- // Compare both Zip Files byte[] zipContentHardDrive = Files.readAllBytes(Paths.get("pathToFile")); byte[] zipContentMemory = baos.toByteArray(); int minLength = Math.min(zipContentMemory.length, zipContentHardDrive.length); if (!Arrays.equals( Arrays.copyOf(zipContentMemory, minLength), Arrays.copyOf(zipContentHardDrive, minLength))) { throw new IOException("The Zip Files are different."); } // --------------------- return zipContentMemory; }catch (Exception e) { System.out.println("Could not create Zip File"); } return null; } } 最后,在我详细介绍我的问题之前,这里是 IOUtil 方法: public static ByteArrayOutputStream createZipFileInMemory(List<File> files) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream( byteArrayOutputStream); for (File file : files) { addZipEntry(zipArchiveOutputStream, file); } zipArchiveOutputStream.finish(); return byteArrayOutputStream; } private static void addZipEntry(ArchiveOutputStream archiveOutputStream, File file) throws IOException { String entryName = file.getName(); ArchiveEntry archiveEntry = new ZipArchiveEntry(file, entryName); archiveOutputStream.putArchiveEntry(archiveEntry); if (file.isFile()) { Files.copy(file.toPath(), archiveOutputStream); } archiveOutputStream.closeArchiveEntry(); } createZipFile 工作完全正常。 我的问题是,我从下载中获得的 zip 文件比我直接在硬盘上创建的文件大 200 字节左右。我也无法打开更大的 zip 文件。用 vim 打开较大的 zip 文件后,我可以看到内容与较小的 zip 文件完全不同: 较小的拉链: " zip.vim 版本 v33 " 浏览 zip 文件路径ToZip " 用光标选择文件并按 ENTER 你好.txt 世界.txt 这是更大的一个: PK^C^D^T^@^H^H^H^@���W^@^@^@^@^@^@^@^@^@^@^@^@ ^@5^@ hello.txtUT^M^@^G���eִ�e���e 我不知道我在内存中创建 zip 文件的方法是否错误,或者传输到 store.config 时是否出现问题。 还有一件事值得注意的是 zipContentHardDrive 和 zipContentMemory 是不同的: zip内容硬盘: [80, 75, 3, 4, 20, 0, 0, 8, 8, 0, -72, -114, -103, 87, 32, 48, 58, 54, 8, 0, 0, 0, 6, 0、0、0、9、0、53、0、104、101、108、108、111、46、116、120、116、85、84、13、0、7、-99、-77、-119 , 101, -42, -76, -119, 101, -99, -77, -119, 101, 10, 0, 32, 0, 0, 0, 0, 0, 1, 0, 24, 0, - 106, 85, -35, -18, 82, 55, -38, 1, 4, 18, -88, -87, 83, 55, -38, 1, -128, 76, -114, -18, 82 , 55, -38, 1, -53, 72, -51, -55, -55, -25, 2, 0, +322 更多] zip内容内存: [80, 75, 3, 4, 20, 0, 8, 8, 8, 0, -72, -114, -103, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0、0、0、9、0、53、0、104、101、108、108、111、46、116、120、116、85、84、13、0、7、-99、-77、-119 , 101, -42, -76, -119, 101, -99, -77, -119, 101, 10, 0, 32, 0, 0, 0, 0, 0, 1, 0, 24, 0, - 106, 85, -35, -18, 82, 55, -38, 1, 4, 18, -88, -87, 83, 55, -38, 1, -128, 76, -114, -18, 82 , 55, -38, 1, -53, 72, -51, -55, -55, -25, 2, 0, +354 更多] 我不确定是否是这样,因为 zip 文件在内存中和不在内存中时通常是不同的。 如果有人能帮助我理解并解决我的问题,我将非常感激。 非常感谢您抽出时间! 更新1 经过以下测试后,我发现由于未知原因,createZipFileInMemory 方法无法像 CoonversionService 中那样工作。 @Test public void testCreateZipFileInMemoryWithFiles() throws IOException { IOUtil.writeFile(graph, PATH_GRAPH_TXT); IOUtil.writeFile(graph, PATH_GRAPH_XML); File fileText = new File(PATH_GRAPH_TXT); File fileXML = new File(PATH_GRAPH_XML); List<File> listOfFiles = new ArrayList<>(); listOfFiles.add(fileText); listOfFiles.add(fileXML); ByteArrayOutputStream zipFileInMemory = IOUtil.createZipFileInMemory(listOfFiles); assertNotNull(zipFileInMemory); // Now let's check if the data stored in the memory is actually the right Zip-file // Therefore let's create an actual Zip-File on our hard drive IOUtil.createZipFile(PATH_CREATED_ZIP, listOfFiles); // Read the content of the created zip file byte[] actualZipContent = Files.readAllBytes(Paths.get(PATH_CREATED_ZIP)); // Compare the contents of the files within the zip ZipInputStream dataOfMemoryZip = new ZipInputStream(new ByteArrayInputStream(zipFileInMemory.toByteArray())); ZipInputStream dataOfHardDriveZip = new ZipInputStream(new ByteArrayInputStream(actualZipContent)); ZipEntry memoryEntry; ZipEntry hardDriveEntry; while ((memoryEntry = dataOfMemoryZip.getNextEntry()) != null) { hardDriveEntry = dataOfHardDriveZip.getNextEntry(); assertEquals(memoryEntry.getName(), hardDriveEntry.getName()); byte[] expectedFileContent = IOUtils.toByteArray(dataOfMemoryZip); byte[] actualFileContent = IOUtils.toByteArray(dataOfHardDriveZip); assertArrayEquals(expectedFileContent, actualFileContent); } } 这里的内容总是一样的。我不明白为什么 ConversionService 类中的内容不同,因为我使用相同的文件和相同的方法。 您创建的 zip 文件的部分十进制转储确实不同。 zipContentMemory 已创建 streamed zip 文件,而 zipContentHarddrive 尚未创建。这足以解释为什么一个 zip 文件可以工作,而另一个却不能。 注意:如果没有看到完整的 zip 文件,就不可能 100% 确定这一点。 zip 文件中可能存在一些其他差异,导致您遇到问题。如果有机会的话,发布完整的 zip 转储。 部分 zipContentHarddrive zip 文件看起来像这样 0000 LOCAL HEADER #1 04034B50 (67324752) 0004 Extract Zip Spec 14 (20) '2.0' 0005 Extract OS 00 (0) 'MS-DOS' 0006 General Purpose Flag 0800 (2048) [Bits 1-2] 0 'Normal Compression' [Bit 11] 1 'Language Encoding' 0008 Compression Method 0008 (8) 'Deflated' 000A Last Mod Date/Time 57E6F1C7 (1474752967) 'Invalid Date or Time' 000E CRC 363A3020 (909783072) 0012 Compressed Size 00000008 (8) 0016 Uncompressed Size 00000006 (6) 001A Filename Length 0009 (9) 001C Extra Length 0035 (53) 001E Filename 'hello.txt' 0027 Extra ID #1 5455 (21589) 'Extended Timestamp [UT]' 0029 Length 000D (13) 002B Flags 07 (7) 'mod access change' 002C Mod Time 65F6CCE2 (1710673122) 'Sun Mar 17 10:58:42 2024' 0030 Access Time 65F6CBA9 (1710672809) 'Sun Mar 17 10:53:29 2024' 0034 Change Time 65F6CCE2 (1710673122) 'Sun Mar 17 10:58:42 2024' 0038 Extra ID #2 000A (10) 'NTFS FileTimes' 003A Length 0020 (32) 003C Reserved 00000000 (0) 0040 Tag1 0001 (1) 0042 Size1 0018 (24) 0044 Mtime 01A5375291A255E9 (118561792965367273) 'Thu Sep 16 07:08:16 1976 536727300ns' 004C Atime 01A53753D6D71204 (118561798421418500) 'Thu Sep 16 07:17:22 1976 141850000ns' 0054 Ctime 01A5375291F14CFF (118561792970542335) 'Thu Sep 16 07:08:17 1976 54233500ns' 部分 zipContentMemory zip 文件看起来像这样 0000 LOCAL HEADER #1 04034B50 (67324752) 0004 Extract Zip Spec 14 (20) '2.0' 0005 Extract OS 00 (0) 'MS-DOS' 0006 General Purpose Flag 0808 (2056) [Bits 1-2] 0 'Normal Compression' [Bit 3] 1 'Streamed' [Bit 11] 1 'Language Encoding' 0008 Compression Method 0008 (8) 'Deflated' 000A Last Mod Date/Time 57E6F1C7 (1474752967) 'Invalid Date or Time' 000E CRC 00000000 (0) 0012 Compressed Size 00000000 (0) 0016 Uncompressed Size 00000000 (0) 001A Filename Length 0009 (9) 001C Extra Length 0035 (53) 001E Filename 'hello.txt' 0027 Extra ID #1 5455 (21589) 'Extended Timestamp [UT]' 0029 Length 000D (13) 002B Flags 07 (7) 'mod access change' 002C Mod Time 65F6CCE2 (1710673122) 'Sun Mar 17 10:58:42 2024' 0030 Access Time 65F6CBA9 (1710672809) 'Sun Mar 17 10:53:29 2024' 0034 Change Time 65F6CCE2 (1710673122) 'Sun Mar 17 10:58:42 2024' 0038 Extra ID #2 000A (10) 'NTFS FileTimes' 003A Length 0020 (32) 003C Reserved 00000000 (0) 0040 Tag1 0001 (1) 0042 Size1 0018 (24) 0044 Mtime 01A5375291A255E9 (118561792965367273) 'Thu Sep 16 07:08:16 1976 536727300ns' 004C Atime 01A53753D6D71204 (118561798421418500) 'Thu Sep 16 07:17:22 1976 141850000ns' 0054 Ctime 01A5375291F14CFF (118561792970542335) 'Thu Sep 16 07:08:17 1976 54233500ns'

回答 1 投票 0

以静默方式更新固定设备所有者管理的 Android 应用程序(在信息亭模式下)

我创建了一个设备所有者应用程序,该应用程序在启动时固定该应用程序,我想从 GitHub 中托管的 apk(而不是 PlayStore)更新 Kiosk 启动器应用程序,我已成功做到了

回答 1 投票 0

HttpResponse Blob

我有一个使用 Angular 13 的应用程序,我在其中向后面发出 POST 请求,我需要获取标头,并获取文件名来自的 Content-Disposition 部分。 因此,我创造...

回答 1 投票 0

无法使用node js 将生成的文件下载到电脑

您好 Stack Overflow 社区, 我目前正在开发一个用作认证系统的 Express.js 应用程序。该应用程序旨在生成 PDF 格式的个性化证书...

回答 1 投票 0

如何使用 Ruby 通过 HTTP 下载文件?

如何使用 Ruby 通过 HTTP 下载文件?

回答 5 投票 0

S3Hook download_file 函数寻找不存在的airflow_tmp 文件夹

我正在尝试使用气流中的S3Hook从S3上的存储桶位置下载文件。 下面是我的代码 def s3_extract(key: str, bucket_name: str, local_path: str) -> str: source_s3_key =...

回答 1 投票 0

仅当目标比源更新时才下载并替换文件

这就是我想要实现的目标: 用户上传file1.jpg到服务器A 如果文件比服务器 B 上已存在的文件新,则使用 wget 服务器 B 仅从服务器 A 下载 file1.jpg 并且

回答 1 投票 0

从外部API下载XLS文件

当我发出 GET 请求时,我的外部 API 返回以下内容: “PK\u0003\u0004 \u0000\u0000\u0000\u0008\u0000f��T��� Y\u0001\u0000\u0000�\u0004\u0000\u0000\u0013\u0000\u0000\u0000[内容_...

回答 1 投票 0

NextJS - 从外部 API 下载 XLS 文件

当我发出 GET 请求时,我的外部 API 返回以下内容: “PK\u0003\u0004 \u0000\u0000\u0000\u0008\u0000f��T��� Y\u0001\u0000\u0000�\u0004\u0000\u0000\u0013\u0000\u0000\u0000[内容_...

回答 1 投票 0

上传文件到 vscode.dev

与编程无关,更多的是如何使用编程工具,但我真的不知道在哪里可以问。我发现自己经常这样做,足以证明寻找解决方案是合理的。 我你...

回答 1 投票 0

该网站如何阻止用户下载视频?

我正在编写一个在线培训程序,我希望用户不要下载视频!这就是为什么我需要一名球员来防止这种情况发生。 我想喜欢这个网站 在这个网站上执行它,视频...

回答 1 投票 0

Angular - 使用 base64 上传/存储/下载文件

我正在使用 Angular 并尝试上传文件(存储在数据库中),然后下载文件。我正在使用 Base 64 编码/解码。看起来它可以工作,但是在我下载文件后,当我...

回答 1 投票 0

如何使用FastAPI在下载文件之前在前端出现选择下载位置的对话框?

我有一个 GET 端点,它应该返回一个巨大的文件(500Mb)。 我正在使用 FileResponse 来执行此操作(为了清晰起见,简化了代码): 异步 def get_file() headers = {“Content-Dispo...

回答 1 投票 0

如何使用FastAPI在下载文件之前在前端出现选择下载位置的对话框?

我有一个 GET 端点,它应该返回一个巨大的文件(500Mb)。 我正在使用 FileResponse 来执行此操作(为了清晰起见,简化了代码): 异步 def get_file() headers = {“Content-Dispo...

回答 1 投票 0

将 Firefox 保存的下载内容恢复到 /tmp

升级到 22.04 LTS 后,ff 的下载行为发生了变化。我读过一些关于此的文章,但没有看到任何与解决我的问题相关的内容。具体来说...

回答 5 投票 0

如何在FastAPI中即时加载文件?

我有一个 GET 端点,它应该返回一个巨大的文件(500Mb)。 我正在使用 FileResponse 来执行此操作(为了清晰起见,简化了代码): 异步 def get_file() headers = {“Content-Dispo...

回答 1 投票 0

Material-UI:芯片组件下载选项不起作用,如何解决下载问题?

我已经使用 UI 上传了文件,我想在一段时间后或立即下载,我已经使用 组件实现了相同的功能,但它不起作用,需要帮助来解决该问题。 **

回答 1 投票 0

文件移动到 IOS 不起作用 - React Native FS

我已经实现了将图像列表作为 pdf 下载到移动存储的方法,android 工作正常,没有任何问题,但 ios 不工作。我为两个操作系统授予了所有必要的权限,但 iOS 没有...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.