How do I download large files from a nginx server?

"front end" is UE4, downloading large files from my nginx server through http protocol. File transfer must be encrypted using base64. Baidu has many transmission methods on the Internet. These methods are all aimed at the case that the front end is a browser. But my current situation is that my server only provides a data interface, and "front end" is not a browser. Baidu"s method is as follows:

1.fread segmented read
2.readfile entire read
3.file_get_counts entire read
4.curl transfer

the data is encrypted through base64, so it seems that segmented transmission can not be realized. We can only read the whole file, encrypt it with base64, and then transfer it. My code is as follows:

public function actionPak()
    {
        set_time_limit(0);
        //
        $post_data = file_get_contents("php://input");
  
       // json
        $json_obj = json_decode($post_data);
        if (isset($json_obj->Num)) {
            $file = \Yii::getAlias("@webroot") . "/pattern/pak/" . $json_obj->Num . ".pak";
            //
            ob_start();
            readfile($file);
            $data = ob_get_contents();
            ob_end_clean();
            return base64_encode($data);
        } else {
            return base64_encode("false");
        }
    }

all methods have been tried except for curl. The problem now is that there is no problem with small file transfer. When the file size is tens to hundreds of megabytes, the transfer will fail. Do you have any advice from the boss? thank you

Php
Jun.24,2021

first of all, find out what caused the failure, whether the transmission was interrupted because of a network problem, or whether it was caused by a timeout due to base64 coding.

in fact, base64 encoding does not make much sense, because it is not encrypted at all. As long as you intercept the data, you can decode it. For security, consider that https, can be re-transmitted by nginx, or you can slice the file and transfer it segment by segment.

Menu