Создание CSV из объекта Java и перемещение в хранилище Azure без промежуточного расположения
Можно ли создать файл типа CSV из объекта Java и переместить его в хранилище Azure без использования временного расположения?
1 ответ
Согласно вашему описанию, кажется, что вы хотите загрузить файл CSV, не занимая при этом ваше локальное пространство. Поэтому я предлагаю вам использовать поток для загрузки файлов CSV в хранилище файлов Azure.
Пожалуйста, обратитесь к примеру кода, как показано ниже:
import com.microsoft.azure.storage.CloudStorageAccount;
import com.microsoft.azure.storage.file.CloudFile;
import com.microsoft.azure.storage.file.CloudFileClient;
import com.microsoft.azure.storage.file.CloudFileDirectory;
import com.microsoft.azure.storage.file.CloudFileShare;
import com.microsoft.azure.storage.StorageCredentials;
import com.microsoft.azure.storage.StorageCredentialsAccountAndKey;
import java.io.File;
import java.io.FileInputStream;
import java.io.StringBufferInputStream;
public class UploadCSV {
// Configure the connection-string with your values
public static final String storageConnectionString =
"DefaultEndpointsProtocol=http;" +
"AccountName=<storage account name>;" +
"AccountKey=<storage key>";
public static void main(String[] args) {
try {
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
// Create the Azure Files client.
CloudFileClient fileClient = storageAccount.createCloudFileClient();
StorageCredentials sc = fileClient.getCredentials();
// Get a reference to the file share
CloudFileShare share = fileClient.getShareReference("test");
//Get a reference to the root directory for the share.
CloudFileDirectory rootDir = share.getRootDirectoryReference();
//Get a reference to the file you want to download
CloudFile file = rootDir.getFileReference("test.csv");
file.upload( new StringBufferInputStream("aaa"),"aaa".length());
System.out.println("upload success");
} catch (Exception e) {
// Output the stack trace.
e.printStackTrace();
}
}
}
Затем я успешно загружаю файл в аккаунт.
Вы также можете обратиться к темам:
1. Можно ли загрузить поток в хранилище BLOB-объектов Azure, не указав его длину заранее?
2. Загрузите BLOB-объект в Azure, используя BlobOutputStream
Надеюсь, это поможет вам.