在java服务中,我试图在azure存储目录中上传文件;因此我写了这样的代码:
import com.azure.core.util.*;
import com.azure.storage.file.share.*;
import com.azure.storage.file.share.models.*;
//Create connexion string
String connectStr ="DefaultEndpointsProtocol=https;AccountName=" + accountName + ";AccountKey=" + accountKey + ";EndpointSuffix=" + endpoint;
//ShareDirectoryClient
ShareDirectoryClient dirClient = new ShareFileClientBuilder().connectionString(connectStr).shareName(shareName).resourcePath(directoryName).configuration(proxyOptions).buildDirectoryClient();
// Create empty file
dirClient.createFile(fileName, body.length());
HTTPS请求必须经过一个代理服务器,所以,我得到这个错误:
"无法运行sendFileInDirectoryProxyTestreactor.core。$ReactiveException: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: no further information: ">
我不能设置/使用全局设置。为了在Java代码中设置代理,我尝试了几种方法,比如使用配置类:
Configuration configuration = new Configuration();
configuration.put("java.net.useSystemProxies", "true");
configuration.put("https.proxyHost", "xxxxxxxxx");
configuration.put("https.proxyPort", "xxxx");
ShareDirectoryClient dirClient = new ShareFileClientBuilder().connectionString(connectStr).shareName(shareName).resourcePath(directoryName).configuration(configuration).buildDirectoryClient();
但这并没有解决问题。我相信这很简单,任何帮助都会很感激。谢谢。圣安德烈。
您需要配置ProxyOptions并在httpClientBuilder上设置它们。我们所有的存储客户端构建器都有一个接受客户端的. httpclient()方法,你可以使用netttyasyncclientbuilder()来构建一个带有所有默认值和代理选项的客户端,它有一个. proxyoptions()方法。请尝试一下,如果你有任何问题,请告诉我。示例:Azure -sdk-for-java/sdk/storage/Azure -storage-blob在main·Azure/Azure -sdk-for-java (github.com)