我正在docs
之后通过app-engine将文件上传到GCS(代码取自here)
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
GcsFileOptions instance = GcsFileOptions.getDefaultInstance();
GcsFilename fileName = getFileName(req);
GcsOutputChannel outputChannel;
outputChannel = gcsService.createOrReplace(fileName, instance);
copy(req.getInputStream(), Channels.newOutputStream(outputChannel));
}
这是复制方法:
private void copy(InputStream input, OutputStream output) throws IOException {
try {
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead = input.read(buffer);
while (bytesRead != -1) {
output.write(buffer, 0, bytesRead);
bytesRead = input.read(buffer);
}
} finally {
input.close();
output.close();
}
}
现在我想将此元数据添加到文件
metadata = "{timestamp:\"01/12/2016\", blabla: 111}"
如何使用上面的代码添加此元数据?
答案 0 :(得分:0)
使用new Builder().addUserMetadata()
的{{1}}内容;
GcsFileOptions.getDefaultInstance()