2017-12-26 12 views
0

JavaオブジェクトからCSVのようなファイルを作成し、一時的な場所を使わずにAzure Storageに移動できますか?JavaオブジェクトからCSVを生成し、中間ロケーションなしでAzure Storageに移動

+0

あなたがこれまでに試したこと(私たちにいくつかのコードを見せてください)とあなたが走っている問題は何かを教えてください。 –

+0

@ GauravMantri現在のシステムは、JavaオブジェクトからCSVファイルを作成し、 "C:\ temp"のようなパスに格納します。私はここからCSVファイルを読んでAzure Storageに移動します。私が今やりたいのは、一時ロケーション部分を削除し、Javaオブジェクトをシリアル化して直接移動させることです。 –

答えて

1

あなたの説明によると、ローカルスペースを使わずにCSVファイルをアップロードしたいと思うようです。ですから、CSVファイルをAzure File Storageにアップロードするためにストリームを使用することをお勧めします。

として以下のサンプルコードを参照してください:

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(); 
     } 
    } 
} 

をそれから私が正常にアカウントにファイルをアップロードします。

enter image description here

また、スレッドを参照してください可能性があります。2. Upload blob in Azure using BlobOutputStream

1. Can I upload a stream to Azure blob storage without specifying its length upfront?は、それはあなたのお役に立てば幸いです。

関連する問題