admin管理员组文章数量:1399499
I am trying upload a file to Azure from a Java function but i dont get it, i am not sure if my local directories or another variables such as "shareName" or "dirName" or "fileName" i was declared incorrectly
i was a follow the next instructions in the apartated Upload a File: Azure documentation.
At runs my code i was receive the next console output:
DEBUG reactorty.resources.PooledConnectionProvider - [id:c341493a, L:/192.168.1.68:56172 - R:wiebs4fefe66q0knduvyeie.file.core.windows/52.239.169.232:443] Channel cleaned, now: 0 active connections, 1 inactive connections and 0 pending acquire requests. uploadFile exception: Status code 404, "?<?xml version="1.0" encoding="utf-8"?><Error><Code>ParentNotFound</Code><Message>The specified parent path does not exist. RequestId:f70e845e-401a-0068-66fd-9d44f5000000 Time:2025-03-26T03:17:18.3651535Z</Message></Error>"
I was try use this code extracted from the Azure oficial web site in the Upload a File aparted
the uploadFile metod is the next:
public static Boolean uploadFile(String connectStr, String shareName,
String dirName, String fileName)
{
try
{
ShareDirectoryClient dirClient = new ShareFileClientBuilder()
.connectionString(connectStr).shareName(shareName)
.resourcePath(dirName)
.buildDirectoryClient();
ShareFileClient fileClient = dirClient.getFileClient(fileName);
fileClient.create(1024);
fileClient.uploadFromFile(fileName);
return true;
}
catch (Exception e)
{
System.out.println("uploadFile exception: " + e.getMessage());
return false;
}
}
and i call the uploadFile method that next way:
String connectionString = "DefaultEndpointsProtocol=https;" +
"AccountName=wisdfdsfsie;" +
"AccountKey=Y9vsdfsdfsdfsdffsdfGdQZK8Lz4DAIwi9A==";
String shareName = "mis-archivos";
String dirName = "hybris/master/mabe";
String fileName = "temp/GR_IMPEXP_25-03-2025.csv";
boolean result = uploadFile(connectionString, shareName, dirName, fileName);
if (result) {
System.out.println("Upload Correct.");
} else {
System.out.println("Upload Failed....");
}
i am still not very clear the form of use the variables as shareName, dirName and fileName. I should set a special configuration into my Microsoft Azure Storage Explorer?
in the string fileName i should put the file to transfer to my Azure Storage?
I am should be create a File Shared Resource in the Microsoft Azure Storage Explorer? how to it?
in the dirName i should set the directory trees set into the file shared resources?
I am a little bit confused in how functions the uploadFiles method.
I am trying upload a file to Azure from a Java function but i dont get it, i am not sure if my local directories or another variables such as "shareName" or "dirName" or "fileName" i was declared incorrectly
i was a follow the next instructions in the apartated Upload a File: Azure documentation.
At runs my code i was receive the next console output:
DEBUG reactorty.resources.PooledConnectionProvider - [id:c341493a, L:/192.168.1.68:56172 - R:wiebs4fefe66q0knduvyeie.file.core.windows/52.239.169.232:443] Channel cleaned, now: 0 active connections, 1 inactive connections and 0 pending acquire requests. uploadFile exception: Status code 404, "?<?xml version="1.0" encoding="utf-8"?><Error><Code>ParentNotFound</Code><Message>The specified parent path does not exist. RequestId:f70e845e-401a-0068-66fd-9d44f5000000 Time:2025-03-26T03:17:18.3651535Z</Message></Error>"
I was try use this code extracted from the Azure oficial web site in the Upload a File aparted
the uploadFile metod is the next:
public static Boolean uploadFile(String connectStr, String shareName,
String dirName, String fileName)
{
try
{
ShareDirectoryClient dirClient = new ShareFileClientBuilder()
.connectionString(connectStr).shareName(shareName)
.resourcePath(dirName)
.buildDirectoryClient();
ShareFileClient fileClient = dirClient.getFileClient(fileName);
fileClient.create(1024);
fileClient.uploadFromFile(fileName);
return true;
}
catch (Exception e)
{
System.out.println("uploadFile exception: " + e.getMessage());
return false;
}
}
and i call the uploadFile method that next way:
String connectionString = "DefaultEndpointsProtocol=https;" +
"AccountName=wisdfdsfsie;" +
"AccountKey=Y9vsdfsdfsdfsdffsdfGdQZK8Lz4DAIwi9A==";
String shareName = "mis-archivos";
String dirName = "hybris/master/mabe";
String fileName = "temp/GR_IMPEXP_25-03-2025.csv";
boolean result = uploadFile(connectionString, shareName, dirName, fileName);
if (result) {
System.out.println("Upload Correct.");
} else {
System.out.println("Upload Failed....");
}
i am still not very clear the form of use the variables as shareName, dirName and fileName. I should set a special configuration into my Microsoft Azure Storage Explorer?
in the string fileName i should put the file to transfer to my Azure Storage?
I am should be create a File Shared Resource in the Microsoft Azure Storage Explorer? how to it?
in the dirName i should set the directory trees set into the file shared resources?
I am a little bit confused in how functions the uploadFiles method.
Share Improve this question edited Mar 26 at 4:45 James Z 12.3k10 gold badges27 silver badges47 bronze badges asked Mar 26 at 3:33 Armando Rojas ValdezArmando Rojas Valdez 31 silver badge1 bronze badge1 Answer
Reset to default 1If you look at the error message, you will notice that you are getting the error about the directory not exist. Before you can upload a file in a directory, the directory must be present in that share.
Please see the code below:
public static Boolean uploadFile(String connectStr, String shareName,
String dirName, String fileName)
{
try
{
ShareDirectoryClient dirClient = new ShareFileClientBuilder()
.connectionString(connectStr).shareName(shareName)
.resourcePath(dirName)
.buildDirectoryClient();
//create directory if it does not exist
dirClient.createIfNotExists();
ShareFileClient fileClient = dirClient.getFileClient(fileName);
fileClient.create(1024);
fileClient.uploadFromFile(fileName);
return true;
}
catch (Exception e)
{
System.out.println("uploadFile exception: " + e.getMessage());
return false;
}
}
本文标签: How to upload a file from java to AzureStack Overflow
版权声明:本文标题:How to upload a file from java to Azure? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744166797a2593585.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论