Skip to content

FileNotFound Exception #1548

@hantsy

Description

@hantsy

Describe the bug

In our application, we have the following similar codes to list and download all files from a S3 bucket.

The code snippets worked well before, but currently I got an FileNotFoundException in the writeToFile line.

client.listObjectsV2(ListObjectsV2Request { bucket = bucketName }).contents?.forEach { obj ->
      client.getObject(
          GetObjectRequest {
              key = obj.key;
              bucket = bucketName
          }
      ) { response ->
          val downloadDir = File(downloadDirPath)
          if (!downloadDir.exists()) {
              downloadDir.mkdirs()
          }
          val outputFile = File(downloadDir, obj.key!!)
          response.body?.writeToFile(outputFile).also { size ->
              log.debug("Downloaded $outputFile ($size bytes) from S3")
          }
      }
  }

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected behavior

Here we want to write the content to the outputFile here which is not existed, but before, which created the files and wrote the content correctly.

Current behavior

Currently it failed to write bytes to files/

Steps to Reproduce

Check the above codes.

Possible Solution

No response

Context

No response

AWS SDK for Kotlin version

1.4.36

Platform (JVM/JS/Native)

JVM

Operating system and version

Ubuntu

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions