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

前端 未结 4 413
猫巷女王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:53

    When you're using SourceFile option at putObject S3Client opens a file, but doesn't close it after operation.

    In most cases you just can unset $client and/or $result to close opened files. But unfortunately not in this case.

    Use Body option instead of the SourceFile.

    // temp file
    $file = fopen($temp_path, "r");
    
    // use resource, not a path
    $result = $client->putObject(array(
            'Bucket'     => self::$bucketName,
            'Key'        => 'screenshot/testing.png',
            'Body'       => $file,
            'ACL'        => 'public-read'
        ));
    );
    
    fclose($file);
    
    unlink($temp_path);
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题