当前位置:网站首页>Batch package and download Alibaba OSS files
Batch package and download Alibaba OSS files
2022-06-13 08:19:00 【Parthenocissus still works】
Where there is a need, there is a way , Bulk download oss file , In the previous chapter, we talked about batch intermittent downloading from the front-end point of view , But there are some problems (1. Bad user experience ,2. The browser configuration needs to be modified for multiple downloads or pop ups , And sometimes there is a risk that the request will be cancelled , It is sometimes difficult for operators to find this problem if they do not verify the number of files , This has certain risks for statistical work ), This article is from the back-end interface , Batch request Ali oss Get the contents of the downloaded file , Package and download the acquired data at one time :
class TestOss extends BaseController
{
// Preliminary survey
public function test()
{
$objectName = 'abc/2021/10/30/G20211030060001231.xlsx';
$object = self::$oss->getObject($this->config['oss']['bucket'], $objectName);
$file = 'abc' . substr($objectName, strrpos($objectName, '.'));
$fp = fopen ($file, 'w');
fwrite($fp, $object);
fclose($fp);
}
// Package download
public function testZip()
{
error_reporting(E_ALL);
ini_set('display_errors', true);
$zip = new ZipArchive;
$tmpFileName = './tmpzip' . mt_rand(100, 999);
$res = $zip->open($tmpFileName, ZipArchive::CREATE);
var_dump(is_file($tmpFileName));
$objectName = 'abc/1077/2021/10/30/G20211030060001231.xlsx';
$object = self::$oss->getObject($this->config['oss']['bucket'], $objectName);
$file = 'abc' . substr($objectName, strrpos($objectName, '.'));
if ($res === TRUE) {
$zip->addFromString($file, $object);
$zip->close();
$tarFile = 'abc.zip';
var_dump(is_file($tmpFileName));
$fileSize = filesize($tmpFileName);
$fp = fopen($tmpFileName, "r");
header("Content-type: application/octet-stream");
header("Accept-Ranges: bytes");
header("Accept-Length: " . $fileSize);
header("Content-Disposition: attachment; filename=" . $tarFile);
$buffer = 1024;
$fileCount = 0;
while (!feof($fp) && $fileCount < $fileSize) {
$fileCon = fread($fp, $buffer);
$fileCount += $buffer;
echo $fileCon;
}
fclose($fp);
unlink($tmpFileName);
} else {
echo 'failed';
}
}
}
(new TestOss())->testZip();
边栏推荐
- Openharmony notes ----------- (I)
- 微服务项目搭建三:自动生成代码
- Dest0g3 520 orientation
- AcWing 1977. 信息中继(基环树,并查集)
- [virt-manager]远程管理启动虚拟机时,鼠标飘逸的问题
- Dest0g3 520迎新赛
- 5. fabric2.2 installation and submission contract (using official demo)
- [virt manager] remote management the problem of the floating mouse when starting the virtual machine
- 母婴用品批发行业使用管理软件提高效率 实现降本增效
- EHD ether coin, the hottest dpoc mining project
猜你喜欢
SQL injection experiment
How to use annotations in word
Word中批注的使用方法
[game theory complete information static game] Nash equilibrium
星巴克创始人:出于安全考量 或不再向非店内消费者开放“公厕”
Win10系统如何修改桌面路径
How about a well-known food material distribution information management system?
Openharmony notes ----------- (I)
1. fabric2.2 comprehensive learning - Preface
生鲜配送分拣管理系统哪家比较强?
随机推荐
Redis interview questions
Founder of Starbucks: no longer open "public toilets" to non store consumers for safety reasons
Dfinity (ICP) identity authentication and ledger quick start-3
Differences between Merkle DAG and Merkle tree
Install cuda+cusp environment and create the first helloword starter project
ERP basic data concept
Bidirectional retransmission step experiment
第115页的gtk+编程例子——最简单的进度条2附带使用Anjuta写gtk程序的步骤
Unity 退出编辑器模式
酒水批发行业应当如何高效管理商品与库存
set实现名单查找与排除
MySQL query exercise
File upload question type
Rust writes near smart contract
批发商为什么要使用订单系统
钉钉小程序 父子传参数对象 子组件页面不更新?
星巴克创始人:出于安全考量 或不再向非店内消费者开放“公厕”
【完全信息静态博弈-Nash均衡的特性】
Notes on MySQL transaction not automatically submitting
MySQL installation and configuration under Windows