{"record":{"id":"ca44c6f2b71eabdd","repo":"FlowiseAI/Flowise","slug":"failed-to-download-file-keyname-from-s3-bucket","errorCode":null,"errorMessage":"Failed to download file ${keyName} from S3 bucket ${bucketName}: ${e.message}","messagePattern":"Failed to download file (.+?) from S3 bucket (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/documentloaders/S3File/S3File.ts","lineNumber":786,"sourceCode":"                    const response = await s3Client.send(getObjectCommand)\n\n                    const objectData = await new Promise<Buffer>((resolve, reject) => {\n                        const chunks: Buffer[] = []\n\n                        if (response.Body instanceof Readable) {\n                            response.Body.on('data', (chunk: Buffer) => chunks.push(chunk))\n                            response.Body.on('end', () => resolve(Buffer.concat(chunks)))\n                            response.Body.on('error', reject)\n                        } else {\n                            reject(new Error('Response body is not a readable stream.'))\n                        }\n                    })\n\n                    fsDefault.mkdirSync(path.dirname(filePath), { recursive: true })\n\n                    fsDefault.writeFileSync(filePath, objectData)\n                } catch (e: any) {\n                    throw new Error(`Failed to download file ${keyName} from S3 bucket ${bucketName}: ${e.message}`)\n                }\n\n                try {\n                    const obj: UnstructuredLoaderOptions = {\n                        apiUrl: unstructuredAPIUrl,\n                        strategy,\n                        encoding,\n                        coordinates,\n                        skipInferTableTypes,\n                        hiResModelName,\n                        includePageBreaks,\n                        chunkingStrategy,\n                        ocrLanguages,\n                        xmlKeepTags,\n                        multiPageSections,\n                        combineUnderNChars,\n                        newAfterNChars,\n                        maxCharacters","sourceCodeStart":768,"sourceCodeEnd":804,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/documentloaders/S3File/S3File.ts#L768-L804","documentation":"Thrown inside S3File's loader.load override when downloading a single object fails. Wraps the underlying error (network, NoSuchKey, access denied, stream error, 'Response body is not a readable stream') and interpolates its message, naming both keyName and bucketName for diagnosis.","triggerScenarios":"GetObjectCommand returns NoSuchKey (wrong/typo key); AccessDenied (IAM lacks s3:GetObject); stream 'error' event fires mid-download; response.Body is not a Readable stream (SDK v3 shape/version mismatch); fsDefault.writeFileSync fails (disk full / path permission).","commonSituations":"Key name typo or wrong folder prefix; bucket in a different region than s3Config; IAM role not granted read; very large file stream timeout; AWS SDK v3 version where Body is a ReadableStream (web) not a Node Readable.","solutions":["Confirm the keyName exists in the bucket (aws s3 ls s3://bucket/keyName).","Verify IAM s3:GetObject permission and that the bucket region matches s3Config.","Check disk space and tempDir writability for writeFileSync.","Ensure the Readable stream check matches your AWS SDK v3 runtime (Node Readable vs web ReadableStream).","Re-throw with { cause: e } to preserve the original stack."],"exampleFix":"// before\n} catch (e: any) {\n  throw new Error(`Failed to download file ${keyName} from S3 bucket ${bucketName}: ${e.message}`)\n}\n// after\n} catch (e: any) {\n  const reason = e instanceof Error ? e.message : String(e)\n  throw new Error(`Failed to download file ${keyName} from S3 bucket ${bucketName}: ${reason}`, { cause: e })\n}","handlingStrategy":"validation","validationCode":"async function verifyObjectAccessible(s3Client, bucket, key) {\n  await s3Client.send(new (require('@aws-sdk/client-s3').HeadObjectCommand)({ Bucket: bucket, Key: key }))\n}","typeGuard":"const { Readable } = require('stream')\nfunction isReadable(body) { return body instanceof Readable }","tryCatchPattern":"try {\n  return await s3FileLoader.load()\n} catch (e) {\n  if (/Failed to download file .* from S3 bucket/.test(e.message)) {\n    throw new Error('S3 object download failed — check key, IAM, and region', { cause: e })\n  }\n  throw e\n}","preventionTips":["Run a HeadObject pre-check to confirm the key exists and is readable.","Ensure IAM s3:GetObject and correct region in s3Config.","Confirm tempDir writability and disk space.","Match the SDK v3 Body stream type to the Readable check."],"tags":["s3","aws-sdk","download","stream","iam"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}