-
Notifications
You must be signed in to change notification settings - Fork 84
fix: 修复文件名为空导致的异常 #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: 修复文件名为空导致的异常 #120
Conversation
- 在 CreateTranscriptionsReq 类中的 of(File file) 方法中增加了设置文件名的逻辑 - 解决TranscriptionService中获取文件名为空,导致的接口返回 {"detail":{"logid":"2025082610304671C0F5314D04A5EED067"},"code":4000,"msg":"The parameter file is invalid. It should follow the format: file. Please review your input."}
WalkthroughUpdates the CreateTranscriptionsReq.of(File) factory to also set fileName from the provided File’s name. No other classes or public APIs were changed. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
api/src/main/java/com/coze/openapi/client/audio/transcriptions/CreateTranscriptionsReq.java (1)
35-37
: Guard against null file and empty filename; prefer clear, actionable failures.Current code will NPE if
file
is null, andFile#getName()
can return an empty string for edge cases (e.g., paths ending with a separator). Add a null check and validate/normalize the derived name to fail fast with a helpful message.Apply this diff within this method:
public static CreateTranscriptionsReq of(File file) { - return CreateTranscriptionsReq.builder().file(file).fileName(file.getName()).build(); + java.util.Objects.requireNonNull(file, "file must not be null"); + String name = file.getName(); + if (name == null || name.isEmpty()) { + java.nio.file.Path p = java.nio.file.Paths.get(file.getPath()); + java.nio.file.Path fn = p.getFileName(); + if (fn != null) { + name = fn.toString(); + } + } + if (name == null || name.isEmpty()) { + throw new IllegalArgumentException("File name cannot be empty"); + } + return CreateTranscriptionsReq.builder().file(file).fileName(name).build(); }Optional alternative using Lombok to reduce verbosity (requires adding
import lombok.NonNull;
):public static CreateTranscriptionsReq of(@NonNull File file) { ... }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
api/src/main/java/com/coze/openapi/client/audio/transcriptions/CreateTranscriptionsReq.java
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: test (Java 17 on Windows)
- GitHub Check: test (Java 11 on Windows)
🔇 Additional comments (2)
api/src/main/java/com/coze/openapi/client/audio/transcriptions/CreateTranscriptionsReq.java (2)
35-37
: Good fix: populating fileName in of(File) addresses the backend 400 for empty filename.Setting
fileName
fromfile.getName()
is the right behavior for multipart uploads and should resolve the reported"The parameter file is invalid"
error when the filename was previously omitted.
35-37
: Content-Disposition filename is correctly wired throughVerified that when using
CreateTranscriptionsReq.of(File file)
, thefileName
set on the request is indeed passed into the multipart builder as the Content-Disposition filename:
- In
api/src/main/java/com/coze/openapi/service/service/file/FileService.java
line 61, the code calls
MultipartBody.Part.createFormData("file", filename, requestFile)
wherefilename
is the second argument passed fromreq.getFileName()
.- In
api/src/main/java/com/coze/openapi/service/service/audio/TranscriptionService.java
line 48, within the privateuploadFile(...)
helper, it likewise calls
MultipartBody.Part.createFormData("file", filename, requestFile)
withfilename
coming fromreq.getFileName()
.Because
CreateTranscriptionsReq.of(File file)
setsfileName
tofile.getName()
, this ensures the downstream multipart upload uses the correct filename and will satisfy the API’s Content-Disposition requirement. No further changes are needed.
Uh oh!
There was an error while loading. Please reload this page.