How to unlock the file after AWS S3 Helper uploading file?

前端 未结 4 442
猫巷女王i
猫巷女王i 2021-01-04 06:36

I am using the official PHP SDK with the official service provider for laravel to upload an image to Amazon S3. The image is temporarily stored on my server and should be de

4条回答
  •  醉酒成梦
    2021-01-04 06:59

    Yes the stream upload locks the file till it finishes, Try either of 2,

    $client = AWS::createClient('s3');
    $fileContent = file_get_contents($temp_path);
    $result = $client->putObject(array(
        'Bucket'     => self::$bucketName,
        'Key'        => 'screenshot/testing.png',
        'Body'       => $fileContent,
        'ACL'        => 'public-read'
    ));
    );
    
    unlink($temp_path);
    

    or

    $client = AWS::createClient('s3');
    $fileContent = file_get_contents($temp_path);
    $result = $client->putObject(array(
        'Bucket'     => self::$bucketName,
        'Key'        => 'screenshot/testing.png',
        'Body'       => $fileContent,
        'ACL'        => 'public-read'
    ));
    );
    
    gc_collect_cycles();
    unlink($temp_path);
    

提交回复
热议问题