【问题标题】:Laravel 5.4:file upload to into aws s3 directly to bucketLaravel 5.4:文件上传到aws s3直接到桶
【发布时间】:2020-05-16 02:32:46
【问题描述】:

我正在尝试将文件上传到 AWS s3 存储桶

public function fileTest(Request $request)
  {

      //this will create folder test inside my bucket and put the contents
      $request->file->store('test','s3');
  }

但是上面的代码会在我的bucket中创建一个名为test的文件夹并将文件放入其中。

但我想直接上传到bucket

$request->file->store('s3');

我已经尝试了上面的代码,但没有成功。

【问题讨论】:

标签: php amazon-web-services amazon-s3 laravel-5.2


【解决方案1】:

解决了我的关注问题

  $s3 = Storage::disk('s3');
  $s3->put('',$request->file);

速记

Storage::disk('s3')->put('',$request->file)

【讨论】:

    【解决方案2】:
    public function uploadFile (Request $request) {
        $file = $request->file('file');
    
        $imageName = 'uploads/' . $file->getClientOriginalName();
    
        Storage::disk('s3')->put($imageName, file_get_contents($file));
        Storage::disk('s3')->setVisibility($imageName, 'public');
    
        $url = Storage::disk('s3')->url($imageName);
    
        return Response::json(['success' => true, 'response' => $url]);
    }
    

    【讨论】:

      【解决方案3】:

      把你的文件放到 s3 服务器上

          $agreement_contract_copy = $request->file('agreement_contract');
          $filename = $id. '/agreement' . '_' . time() . '.pdf';
          $student->agreement_copy = $filename;
          $student->save();
          Storage::disk('s3')->put($filename, file_get_contents($agreement_copy));
      

      如果您不能定义为公共,则默认将其存储为私有,当您使用私有方法时,在文件获取时间使用临时方法如下。 获取您的文件

      Storage::disk('s3')->temporaryUrl
          ($student->agreement_copy, \Carbon\Carbon::now()->addMinutes(5))
      

      $student->agreement_copy

      测试

      【讨论】:

        【解决方案4】:

        在一个非常简短的解决方案中。

        Storage::disk('s3')->put("destination_path", file_get_contents("BinaryResourse"));
        

        【讨论】:

        猜你喜欢
        • 2020-10-10
        • 2021-02-07
        • 2018-08-19
        • 2019-10-23
        • 2018-04-25
        • 2016-04-07
        • 2013-02-02
        • 2018-09-30
        • 2019-12-06
        相关资源
        最近更新 更多