gpt4 book ai didi

java - 如何使用java上传dropbox中的多个文件

转载 作者:行者123 更新时间:2023-12-02 12:03:13 24 4
gpt4 key购买 nike

我创建了一个java Cucumber Maven项目。现在我想在测试脚本执行完成后将所有报告推送到保管箱中。

我的主要目标是将报告文件夹推送到 Dropbox 上。

我正在使用以下 Maven 依赖项:

<dependency>
<groupId>com.dropbox.core</groupId>
<artifactId>dropbox-core-sdk</artifactId>
<version>1.7.2</version>
</dependency>

我知道这是旧的依赖项,但 Dropbox 提供的代码仅受此库支持。更高版本显示错误或已弃用的方法。

来源:

https://www.dropbox.com/developers-v1/core/start/java

我使用的代码如下:

public class DropBoxUpload {
public static void main(String[] args) throws IOException, DbxException {
// Get your app key and secret from the Dropbox developers website.
final String APP_KEY = "MyAppKey";
final String APP_SECRET = "MyAppSecretKey";

DbxAppInfo appInfo = new DbxAppInfo(APP_KEY, APP_SECRET);

DbxRequestConfig config = new DbxRequestConfig("JavaTutorial/1.0",
Locale.getDefault().toString());
DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);

// Have the user sign in and authorize your app.
String authorizeUrl = webAuth.start();
System.out.println("1. Go to: " + authorizeUrl);
System.out.println("2. Click \"Allow\" (you might have to log in first)");
System.out.println("3. Copy the authorization code.");

String code = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();

// This will fail if the user enters an invalid authorization code.
DbxAuthFinish authFinish = webAuth.finish(code);
String accessToken = authFinish.accessToken;

DbxClient client = new DbxClient(config, accessToken);

System.out.println("Linked account: " + client.getAccountInfo().displayName);

File inputFile = new File("working-draft.txt");
FileInputStream inputStream = new FileInputStream(inputFile);
try {
DbxEntry.File uploadedFile = client.uploadFile("/magnum-opus.txt",
DbxWriteMode.add(), inputFile.length(), inputStream);
System.out.println("Uploaded: " + uploadedFile.toString());
} finally {
inputStream.close();
}

DbxEntry.WithChildren listing = client.getMetadataWithChildren("D:\\MavenJenkinsCI\\target\\cucumber-html-reports");
System.out.println("Files in the root path:");
for (DbxEntry child : listing.children) {
System.out.println(" " + child.name + ": " + child.toString());
}

FileOutputStream outputStream = new FileOutputStream("magnum-opus.txt");
try {
DbxEntry.File downloadedFile = client.getFile("/magnum-opus.txt", null,
outputStream);
System.out.println("Metadata: " + downloadedFile.toString());
} finally {
outputStream.close();
}
}

问题是当我运行这段代码时。它停留在下面一行:

   String code = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();

知道为什么吗?

环境

  • 窗口 10
  • Java 8

如果您有任何解决方法,请分享。

这真的很有帮助。

最佳答案

Greg 提供了正确的依赖项和示例,引导我按要求完成任务。

新版本:

https://github.com/dropbox/dropbox-sdk-java

这里有一个上传示例:

https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/upload-file/src/main/java/com/dropbox/core/examples/upload_file/Main.java

我还在下面添加了一篇文章,它在集成过程中对我有帮助:

http://blog.camilolopes.com.br/tag/dropbox-token/

关于java - 如何使用java上传dropbox中的多个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47096630/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com