2017-12-26 7 views
0

Java 오브젝트에서 CSV와 같은 파일을 생성하고 임시 위치를 사용하지 않고 Azure Storage로 이동할 수 있습니까?Java 오브젝트에서 CSV를 생성하고 중간 위치없이 Azure Storage로 이동

+0

지금까지 시도한 내용 (일부 코드 표시)과 현재 실행중인 문제는 무엇입니까? –

+0

@GauravMantri 현재 시스템은 Java Objects에서 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?은 당신을 도움이되기를 바랍니다.

관련 문제