Laravel and AWS PHP SDK - Unable to delete a local file after it was uploaded to S3

Oren Reuveni

I am trying to delete a file from a local directory right after I have uploaded it to AWS S3. When I run it on Vagrant I get an error = Text-file:busy, and when I run it on xampp I get the error :permission denied. For some reason the AWS S3 PutObject method is not releasing the file handle. I have tried to unset the s3 object but that didn't work.

Here is the code:

    $tempName = public_path().'/path/to/file'

    //Initialize AWS
    $s3 = AWS::createClient('s3');


    //Upload image to AWS

    try {
        $reponse = $s3->putObject(array(
            'Bucket'       => 'zotamoda',
            'Key'          => $productImage->image_folder."/".$productImage->image_name,
            'SourceFile'   => $tempName,
            'ACL'          => 'public-read',
        ));
    } catch (S3Exception $e) {
        // The AWS error code (e.g., )
        echo $e->getAwsErrorCode() . "\n";
        // The bucket couldn't be created
        echo $e->getMessage() . "\n";
    }


    //Delete image from temporary location
    unlink($tempName);
Kevin Lee

You could try:

Storage::disk('s3')->put($productImage->image_folder."/".$productImage->image_name, file_get_contents($tempName), 'public');
unlink($tempName);

or, assuming that $tempName is relative to your project root:

Storage::disk('local')->delete($tempName)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

AWS Lambda and S3 - uploaded pdf file is blank/corrupt

From Java

AWS Lambda and S3 - uploaded pdf file is blank

From Java

AWS SDK for Java version 2 - Delete S3 "folder" or Delete multiple S3 objects

From Java

Spring Boot + AWS S3: Unable to delete files in the bucket

From Dev

Delete an uploaded file after downloading it from Flask

From Dev

AWS PHP SDK: Limit S3 file upload size in presigned URL

From Dev

AWS S3 cannot delete objects in bucket via PHP SDK

From Dev

Event based trigger of AWS Glue Crawler after a file is uploaded into a S3 Bucket?

From Dev

PHP Laravel Uploading File to AWS S3 Asyncronous

From Dev

Unable to upload a pdf file to AWS s3 bucket - PHP

From Dev

Php laravel Upload file directly to AWS S3 bucket

From Dev

php delete only uploaded file on a specific path

From Dev

Delete multiple objects Amazon s3 PHP SDK

From Dev

PHP I can't delete uploaded file

From Dev

Grant IAM User Permissions to AWS S3 File Through AWS PHP SDK

From Dev

AWS PHP SDK upload file to S3 confusing errors

From Dev

How To Delete Uploaded File On Local Host Along With User Account In Php

From Dev

Laravel - Delete local file after served to client

From Dev

Uploaded img not delete after update on laravel 5.4

From Dev

Setting aws s3 file permission to public after upload in Laravel

From Dev

Uploading File in AWS S3 SDK

From Dev

Get the uploaded file from AWS S3 after it has been uploaded

From Dev

Laravel cant delete file in remote url using Storage::('s3')->delete($files); but can delete when using aws command

From Dev

Get URL of uploaded file to S3 (after the file has been uploaded)

From Dev

Php S3 SDK download file : curl_multi_exec(): Unable to create temporary file, AWS HTTP error: cURL error 23: Failed writing body (7744 != 16360)

From Dev

AWS S3 file recently uploaded not updated

From Dev

python unable to extract zip file uploaded to aws s3 bucket

From Dev

Return URL from file uploaded to AWS S3

From Dev

How do I get a file from S3 with aws-sdk-php?

Related Related

  1. 1

    AWS Lambda and S3 - uploaded pdf file is blank/corrupt

  2. 2

    AWS Lambda and S3 - uploaded pdf file is blank

  3. 3

    AWS SDK for Java version 2 - Delete S3 "folder" or Delete multiple S3 objects

  4. 4

    Spring Boot + AWS S3: Unable to delete files in the bucket

  5. 5

    Delete an uploaded file after downloading it from Flask

  6. 6

    AWS PHP SDK: Limit S3 file upload size in presigned URL

  7. 7

    AWS S3 cannot delete objects in bucket via PHP SDK

  8. 8

    Event based trigger of AWS Glue Crawler after a file is uploaded into a S3 Bucket?

  9. 9

    PHP Laravel Uploading File to AWS S3 Asyncronous

  10. 10

    Unable to upload a pdf file to AWS s3 bucket - PHP

  11. 11

    Php laravel Upload file directly to AWS S3 bucket

  12. 12

    php delete only uploaded file on a specific path

  13. 13

    Delete multiple objects Amazon s3 PHP SDK

  14. 14

    PHP I can't delete uploaded file

  15. 15

    Grant IAM User Permissions to AWS S3 File Through AWS PHP SDK

  16. 16

    AWS PHP SDK upload file to S3 confusing errors

  17. 17

    How To Delete Uploaded File On Local Host Along With User Account In Php

  18. 18

    Laravel - Delete local file after served to client

  19. 19

    Uploaded img not delete after update on laravel 5.4

  20. 20

    Setting aws s3 file permission to public after upload in Laravel

  21. 21

    Uploading File in AWS S3 SDK

  22. 22

    Get the uploaded file from AWS S3 after it has been uploaded

  23. 23

    Laravel cant delete file in remote url using Storage::('s3')->delete($files); but can delete when using aws command

  24. 24

    Get URL of uploaded file to S3 (after the file has been uploaded)

  25. 25

    Php S3 SDK download file : curl_multi_exec(): Unable to create temporary file, AWS HTTP error: cURL error 23: Failed writing body (7744 != 16360)

  26. 26

    AWS S3 file recently uploaded not updated

  27. 27

    python unable to extract zip file uploaded to aws s3 bucket

  28. 28

    Return URL from file uploaded to AWS S3

  29. 29

    How do I get a file from S3 with aws-sdk-php?

HotTag

Archive