繁体   English   中英

Laravel 5.4:文件上传到aws s3 直接到bucket

[英]Laravel 5.4:file upload to into aws s3 directly to bucket

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

public function fileTest(Request $request)
  {

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

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

但是我想直接上传到bucket

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

我试过上面的代码,但没有奏效。

通过以下解决了我的问题

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

速记

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

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]);
}

将您的文件放在 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

已测试

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM