Document file content response handling#1874
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c611b0a36d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| ```ts | ||
| const response = await client.files.content('file-abc123'); | ||
| const fileContents = await response.text(); |
There was a problem hiding this comment.
Use a binary-safe read method in file content example
Reading files.content() with response.text() only works for UTF-8 text files; for binary uploads (for example images, PDFs, or arbitrary user_data bytes), this decodes and corrupts the original byte stream. Since this snippet is presented as the general way to retrieve file contents, users following it for non-text files will get damaged data; the example should use a binary-safe method (such as arrayBuffer()) or clearly scope .text() to text-only files.
Useful? React with 👍 / 👎.
c611b0a to
f3616cd
Compare
Summary
client.files.content()returns a web-standardResponseand show reading it with.text()FileContentalias with the actual response typeCloses #958.
Validation
git diff --checknpx --yes prettier@3.7.1 --check src/resources/files.ts./node_modules/.bin/tsc --noEmit --pretty false --target es2020 --lib es2020 --module commonjs --moduleResolution node --esModuleInterop --strict --skipLibCheck src/resources/files.tsNote: full
tsc --noEmitstill requires optional example dependencies such as@azure/identity,express, andnext.