I want to combine files retrieved from the S3 server.

Asked 2 years ago, Updated 2 years ago, 108 views

I wanted to combine the files I got from the S3 server with the files I uploaded. I have created the following code.

public function uploadJoin(Request$request)
{
    $file=$request->file('file');
    $content=\Storage::disk('s3')->get($file_name);
    
    $data=file_get_contents($content);
    $data.=file_get_contents($file);
    
    \Storage::disk('s3') - > put($file_name,$data);
    
    return [
        'message' = > 'ok',
    ];
}

However, the file merge "file_get_contents() expectations parameter 1 to be a valid path" has failed to merge.
How do I treat files retrieved from an S3 server as binary data?

Thank you for your cooperation.

php aws laravel amazon-s3

2022-09-30 18:18

2 Answers

If I translate the error directly, I feel like I should specify a valid path for the first parameter of file_get_contents(), so I think the parameter of file_get_contents() is simply wrong.
Have you checked the specifications of the function?
PHP:file_get_contents-Manual


2022-09-30 18:18

Let's look at the return value of the get method.

public function get($path,$lock=false)
{
    if($this->isFile($path)){
        return $lock ?$this->sharedGet($path):file_get_contents($path);
    }

    through new FileNotFoundException("File does not exist at path {$path}.";
}

Filesystem.php

You can see that $lock returns the value of the sharedGet method if true and the file_get_contents function if false.

Because $lock has a specified value of false, the return value of the file_get_contents function is substituted for the $content of the code you provided.

So what do you mean?
The return value of the get method is the contents of the first argument file, so if you put it in the file_get_contents function, you get the error "No such file!"


2022-09-30 18:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.