How to correctly download an audio file from S3 bucket using java sdk?

0

I uploaded a sample audio.mp3 file to a S3 bucket. I am trying to download that file using java sdk. The file is getting downloaded, however when I play it there are some weird sound glitches which are not present in the original audio. What am I missing?

String key = "audio.mp3";
    InputStream s3ObjectInputStream = s3Client.getObject("audio-bucket", key).getObjectContent();
    byte[] buffer = new byte[1024000];
    try {
        Path currentRelativePath = Paths.get("");
        String path = currentRelativePath.toAbsolutePath() + "/temp.mp3";
        File targetFile = new File(path);
        OutputStream outStream = new FileOutputStream(targetFile);
        while ((s3ObjectInputStream.read(buffer)) != -1) {
            outStream.write(buffer);
        }
        return buffer;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
질문됨 일 년 전116회 조회
답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠