我有以下代码:
String fullFileUrl = fileUrl;
Storage storage = StorageServiceHolder.getStorage();
BlobId blobId = GCSHelper.uri2blobId(fullFileUrl);
while (!queue.isEmpty()) {
try {
String line = queue.poll(1000, TimeUnit.SECONDS);
InputStream inputStream = new ByteArrayInputStream(line.getBytes());
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
Blob blob = storage.create(blobInfo, inputStream);
} catch (InterruptedException e) {
log.error("Get interrupt while writing to Goolge Cloud Storage" + e.getMessage(), e);
}
因为我是逐行上传数据的,所以每次都会删除之前的数据并结束while循环,GCS中的文件只包含最后一行。
如何逐行上传并将其附加到现有数据中?
我设法使用管道而不是队列来解决它:
private PipedInputStream inStream;
inStream = .....
String fullFileUrl = fileUrl;
Storage storage = StorageServiceHolder.getStorage();
BlobId blobId = GCSHelper.uri2blobId(fullFileUrl);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
Blob blob = storage.create(blobInfo, inStream);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)