2016-04-11 14 views
1
私は、次のコードを使用してい

、Googleのクラウドストレージ - javaの

GcsService gcsService = GcsServiceFactory.createGcsService(); 
    GcsFilename filename = new GcsFilename(BUCKETNAME, fileName); 
    GcsFileOptions options = new GcsFileOptions.Builder() 
     .mimeType(contentType) 
     .acl("public-read") 
     .addUserMetadata("myfield1", "my field value") 
     .build(); 
    @SuppressWarnings("resource") 
    GcsOutputChannel outputChannel = 
     gcsService.createOrReplace(filename, options); 
    outputChannel.write(ByteBuffer.wrap(byteArray)); 
    outputChannel.close(); 

問題は、私はビデオファイルを保存しようとすると、私は、ByteArrayにファイルを保存しなければならないことですメモリの問題を引き起こす可能性があります。

しかし、私はストリームと同じことを行うためのインターフェイスを見つけることができません。

質問:

  1. は私がのAppEngineのSRVにMEMの問題を心配すべきか、彼らはMEMで1分のビデオを維持することができますか?

  2. バイト配列の代わりにストリームを使用できますか?どうやって?

  3. バイト配列を実際のバッファとして使用し、チャンクを読み込んでGCSにアップロードすると、バイトがbyte[] byteArray = IOUtils.toByteArray(stream);として読み取られますか?それ、どうやったら出来るの?

答えて

0

使用可能なメモリ量は、設定したappengineインスタンスの種類によって異なります。あなたができるなら、このデータをストリーミングすることは良い考えのようです。

ないGcsService APIについての確認ができますが、のgcloudストレージAPIを使用してこれを行うことができようになっています https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/gcloud-java-storage/src/main/java/com/google/cloud/storage/Storage.java

このコード(未テスト)うまくいくかもしれない...

final BlobInfo info = BlobInfo.builder(bucket.getBucketName(), "name").contentType("image/png").build(); 

final ReadableByteChannel src = Channels.newChannel(stream); 
final WriteChannel dst = gcsStorage.writer(info); 

fastChannelCopy(src, dst); 

private void fastChannelCopy(final ReadableByteChannel src, final WritableByteChannel dest) throws IOException { 
    final ByteBuffer buffer = ByteBuffer.allocateDirect(16 * 1024); 
    while (src.read(buffer) != -1) { 
     buffer.flip();  // prepare the buffer to be drained 
     dest.write(buffer); // write to the channel, may block 
     // If partial transfer, shift remainder down 
     // If buffer is empty, same as doing clear() 
     buffer.compact(); 
    } 
    // EOF will leave buffer in fill state 
    buffer.flip(); 

    // make sure the buffer is fully drained. 
    while (buffer.hasRemaining()) { 
     dest.write(buffer); 
    } 
} 
+0

注ブロブことAPIはこれ以上サポートされていません - 私はこのコードは動作しないと思います。 –

+1

これはBLOB APIではありません。 BlobInfoという名前のクラスが見つかったとしても、これはサポートされていないblob APIであるとは限りません。私は現在、大量のトラフィックを取得する運用システムでこのAPIを使用しています。ここをクリックしてダウンワードを再考してください:http://googlecloudplatform.github.io/gcloud-java/0.2.0/index.html – depsypher

関連する問題