【发布时间】:2023-03-31 10:53:01
【问题描述】:
我正在尝试通过传递文件 ID 从 Box 下载文件,但出现以下错误。虽然我能够从 Box 中获取文件夹项目并能够成功获取文件夹内的所有文件名,但这表明我的应用程序和 Box api 之间存在网络连接。同样的代码在本地机器上也能按预期工作,但在将代码迁移到云端时无法正常工作。
下载 API 是否使用与获取文件夹项目不同的端口? Box API 文档告诉所有 API 都使用 https。
INFO | jvm 1 | main | 2019/08/08 11:26:32.626 | com.box.sdk.BoxAPIException: Couldn't connect to the Box API due to a network error.
INFO | jvm 1 | main | 2019/08/08 11:26:32.626 | at com.box.sdk.BoxAPIRequest.trySend(BoxAPIRequest.java:551)
INFO | jvm 1 | main | 2019/08/08 11:26:32.626 | at com.box.sdk.BoxAPIRequest.handleRedirect(BoxAPIRequest.java:615)
INFO | jvm 1 | main | 2019/08/08 11:26:32.626 | at com.box.sdk.BoxAPIRequest.trySend(BoxAPIRequest.java:571)
INFO | jvm 1 | main | 2019/08/08 11:26:32.627 | at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:354)
INFO | jvm 1 | main | 2019/08/08 11:26:32.627 | at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:329)
INFO | jvm 1 | main | 2019/08/08 11:26:32.627 | at com.box.sdk.BoxFile.download(BoxFile.java:295)
INFO | jvm 1 | main | 2019/08/08 11:26:32.627 | at com.box.sdk.BoxFile.download(BoxFile.java:283)
INFO | jvm 1 | main | 2019/08/08 11:26:32.627 | at com.ge.hc.integration.service.impl.BoxIntegrationSerImpl.getBoxFileByFileID(BoxIntegrationSerImpl.java:188)
INFO | jvm 1 | main | 2019/08/08 11:26:32.727 | Caused by: java.net.ConnectException: Connection timed out (Connection timed out) (local port 38216 to address 0.0.0.0, remote port 443 to address 107.152.27.200)
INFO | jvm 1 | main | 2019/08/08 11:26:32.727 | at java.net.PlainSocketImpl.socketConnect(Native Method)
INFO | jvm 1 | main | 2019/08/08 11:26:32.727 | at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
INFO | jvm 1 | main | 2019/08/08 11:26:32.727 | at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
INFO | jvm 1 | main | 2019/08/08 11:26:32.727 | at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
INFO | jvm 1 | main | 2019/08/08 11:26:32.727 | at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
INFO | jvm 1 | main | 2019/08/08 11:26:32.727 | at java.net.Socket.connect(Socket.java:857)
INFO | jvm 1 | main | 2019/08/08 11:26:32.727 | at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666)
INFO | jvm 1 | main | 2019/08/08 11:26:32.727 | at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
INFO | jvm 1 | main | 2019/08/08 11:26:32.727 | at sun.net.www.http.HttpClient.openServer(HttpClient.java:474)
INFO | jvm 1 | main | 2019/08/08 11:26:32.727 | at sun.net.www.http.HttpClient.openServer(HttpClient.java:569)`
用于文件下载的代码 sn-p(在 boxFile.download(stream); 处抛出错误的那个)--
String fileDownloadLocation = siteConfigService.getProperty(FILEDOWNLOADLOCATION);
File file = null;
BoxAPIConnection boxConnection = new BoxAPIConnection(accessToken);
FileOutputStream stream;
try
{
BoxFile boxFile = new BoxFile(boxConnection, fileID);
BoxFile.Info info = boxFile.getInfo();
LOG.info("downloading file to -"+fileDownloadLocation+info.getName());
stream = new FileOutputStream(fileDownloadLocation+info.getName());
//LOG.info(stream);
boxFile.download(stream);
stream.close();
file = new File(fileDownloadLocation+info.getName());
}
代码 sn-p 获取文件夹项目(正在工作并打印文件名的项目)--
public List<Info> getFolderItems(String accessToken, String folderID) {
List<Info> fileList = new ArrayList<Info>();
BoxAPIConnection boxConnection = new BoxAPIConnection(accessToken);
BoxFolder folder = new BoxFolder(boxConnection, folderID);
for (BoxItem.Info itemInfo : folder) {
if (itemInfo instanceof BoxFile.Info) {
BoxFile.Info fileInfo = (BoxFile.Info) itemInfo;
fileList.add(fileInfo);
LOG.info("***FILE NAME-"+fileInfo.getName());
} else if (itemInfo instanceof BoxFolder.Info) {
BoxFolder.Info folderInfo = (BoxFolder.Info) itemInfo;
}
}
return fileList;
}
【问题讨论】:
-
您能发布用于下载文件的代码部分吗?
-
嗨,john,添加了代码 sn-ps
标签: java networking firewall box-api box