fopen and fputs for Amazon S3 by Laravel

Asked

Viewed 171 times

0

In php, is it possible to send an image file, obtained by returning a request by Curl, directly to a S3 Bucket using Laravel methods? If yes, how to do?

  • Detail, Laravel has a powerful feature to work with Buckets on S3, using file Storage just set the disk drive to S3 and have the environment configured correctly.

  • Maybe this question will help you: https://answall.com/questions/194939/erro-ao-enviar-arquivos-para-servidor-aws-s3-nolaravel

  • Thank you Marcelo, I used this resource to solve my problem.

1 answer

0


I was able to solve the problem without using fopen/fputs, just by taking the return of curl_exec and using it in the file Storage of the file for storage:

  private function FileUpload($path, $url){
   $curl = curl_init();
   curl_setopt($curl, CURLOPT_URL, $url);
   curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
   curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/6.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050414 Firefox/1.0.3");
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
   $content = curl_exec($curl);
   if (curl_error($curl)) {
     return false;
   }
   curl_close($curl);
   Storage::disk('s3')->put($path, $content);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.