feat: add kintone-upload-file tool - #562
Open
Tom8810 wants to merge 2 commits into
Open
Conversation
Tom8810
requested review from
chihiro-adachi and
shabaraba
and removed request for
a team
August 25, 2026 04:28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The server could already pull attachments out of kintone with
kintone-download-file, but there was no way to push a file back in. Attaching a file to a record, a space, or an app setting requires afileKeyfrom the File REST API, and without an upload tool that key could never be obtained—so any workflow that produced a file locally (a generated report, an edited spreadsheet, a file downloaded from another app) dead-ended at the point of attaching it.This adds the missing half of the file round trip. The file is read from the local filesystem and streamed to kintone's temporary storage, so the file contents never pass through the conversation, and the model only handles the resulting
fileKey.What
kintone-upload-file: uploads one local file to kintone's temporary storage via the File REST API (POST /k/v1/file.json) and returns itsfileKey, along with the registeredfileNameand thefileSizein bytes. Only a single file can be uploaded per call, so the tool is meant to be called repeatedly for multiple files.filePathaccepts an absolute path, or a bare file name resolved againstKINTONE_ATTACHMENTS_DIR(the same directorykintone-download-filewrites to, so a downloaded file can be re-uploaded by name). A relative path with noKINTONE_ATTACHMENTS_DIRconfigured is rejected with an explicit error.fileNameis optional and defaults to the base name offilePath. It must not contain a path separator, and a non-ASCII name is sent as UTF-8.fileKeyis temporary-storage-scoped and is a different kind of key from the attachmentfileKeyreturned by record retrieval (a retrieval key cannot be re-uploaded here), that uploading itself needs no specific permission, and that an unattached file is deleted after 3 days while still counting toward the domain's disk usage.uploadFileto the mock client insrc/__tests__/utils.tsso file-related tools can be tested against it.src/tools/index.tsand updatemanifest.json,README.md, andREADME_en.md.KINTONE_ATTACHMENTS_DIR-relative paths, thefileNameoverride including a non-ASCII name, and each error path (missingKINTONE_ATTACHMENTS_DIR, file not found, directory instead of file, path separator infileName, API failure).How to test
KINTONE_ATTACHMENTS_DIRto a directory containing a file, and configureKINTONE_BASE_URLwith credentials for a test app that has an attachment field.kintone-upload-filewith an absolutefilePathand confirm afileKeyis returned and thatfileName/fileSizematch the file on disk.KINTONE_ATTACHMENTS_DIR. UnsetKINTONE_ATTACHMENTS_DIRand confirm a relative path is rejected with a clear error.fileKeyas the value of an attachment field viakintone-add-records(orkintone-update-records) and confirm the file is attached and downloadable, then confirmkintone-download-filebrings it back and that file can be uploaded again by name.fileName(including a non-ASCII one such as見積書.pdf) and confirm that is the name registered in kintone, not the base name offilePath.fileNamecontaining/each fail before any request is sent.pnpm lintandpnpm testat the repo root.Checklist
pnpm lintandpnpm teston the root directory.