Skip to content
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

任务附件上传丢失文件名 #151

Open
jiacheo opened this issue Oct 24, 2024 · 4 comments
Open

任务附件上传丢失文件名 #151

jiacheo opened this issue Oct 24, 2024 · 4 comments

Comments

@jiacheo
Copy link

jiacheo commented Oct 24, 2024

你们SDK 底层处理是啥逻辑,没有获取文件名之类的,上传到任务里之后,所有附件都显示为 unknown

image
@jiacheo
Copy link
Author

jiacheo commented Oct 24, 2024

image 这个 ReqTranslator 貌似完全不设置fileName 啊。。你好歹把文件名读取一下吧。。。

@jiacheo
Copy link
Author

jiacheo commented Oct 25, 2024

image 在 OkHttpTransport 中,读取的是FormDataFile.getFileName 而不是 finalFile.getName(),所以前面没设置,后面就都是 unknown 了。

@jiacheo
Copy link
Author

jiacheo commented Oct 25, 2024

image

FormDataFile 这个代码是实习生写的吗? setFileName 变成了 this.fieldName = ...., 眼神不好咋看出来,这种 SDK 性质的包,用自动生成工具不好吗?这样才能跟实际 API保持完全一致性,靠人总会出问题。

@jiacheo
Copy link
Author

jiacheo commented Oct 25, 2024

workaround:

仿照 com.lark.oapi.core.httpclient.OkHttpTransport 实现一个 IHttpTransport, 将其中构建 multipart 的代码改成

           for (FormDataFile file : ((FormData) body).getFiles()) {
                final File finalFile = file.getFile();
                builder.addFormDataPart(file.getFieldName(),
                        finalFile.getName()
                        , RequestBody.create(MediaType.parse("application/octet-stream"), finalFile));
            }

在构建 Client 的时候,使用 Client.newBuilder(...).httpTransport(new 自定义的Transport()).build()

相当于不使用系统自带的 OKHttpTransport,用自定义的。

注意这个 workaround 只能说上传之后不会 unknown,但不支持自定义 filename,根据实际被上传到文件名来显示。但至少是一个 workaround 了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant