2017-10-17 25 views
0

azureファイルストレージからPDFファイルをダウンロードするにはどうすればよいですか?私は方法があることを知っていますdownloadText()しかしそれはpdfファイルを壊します。私は紺碧の上にアップロードされたファイルをダウンロードするコードを書いて、私はdownloadText()メソッドを使用しましたが、ここでは機能しません。azure用java apiを使用してPDFファイルをダウンロードできません

ただし、pdfファイルをダウンロードしますが、ファイルが破損しているか破損しています。私がやろうとしています

コードサンプル:

CloudFileDirectory sampleDir = rootDir.getDirectoryReference(path); 
         //Get a reference to the file you want to download 
         CloudFile file = sampleDir.getFileReference(fileStorageBean.getUniqueFileIdentifier()); 
         //get file contents from azure file. 
         String fileContent = file.downloadText(); 
         ESAPI.httpUtilities().setHeader(response, "Content-Disposition","attachment;"); 

         response.setContentType(fileStorageBean.getMimeType()); 
         response.setContentLength(file.getStreamWriteSizeInBytes()); 
       InputStream in = new ByteArrayInputStream(fileContent.getBytes()); 
+0

テキストファイルとしてダウンロードする代わりに、バイト配列に直接ダウンロードするか、ストリームにダウンロードしてみてください。 http://azure.github.io/azure-storage-java/com/microsoft/azure/storage/file/CloudFile.html#downloadToByteArray(byte []、int)。 HTH。 –

+0

ありがとうGaurav ...はい、問題がどこにあったのですか... downloadText()。 –

答えて

0

あなたはAzure File Storageからローカルへのあなたのpdfファイルをダウンロードするためにfile.downloadToFileメソッドを使用することができます。

サンプルコード:

CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString); 

CloudFileClient fileClient = storageAccount.createCloudFileClient(); 

CloudFileShare share = fileClient.getShareReference("test"); 

CloudFileDirectory rootDir = share.getRootDirectoryReference(); 

CloudFile file = rootDir.getFileReference("testFile.pdf"); 

File sourceFile = new File("E:\\AzureFile\\f.pdf"); 

file.downloadToFile(sourceFile.getAbsolutePath()); 

それとも、ストリームにファイルをダウンロードするためにfile.downloadメソッドを使用することができます。

希望します。

+0

ジェイ・ゴングありがとうございました。出来た! –

+0

@ShashiShekhar素晴らしいです!あなたはForum.Haveで他人の参照のための私の答えをマークすることができました良い一日! –

関連する問題