fix S3 file writing problem