我正在尝试使用 Google Cloud Storage Client Library 将字节数组“上传”到本地 GAE/J(1.8.1,Eclipse Juno)开发服务器:
byte[] byteContent = new byte[] {1, 2, 3, 4, 5};
GcsFilename fileName = new GcsFilename("MyBucket", "foo");
GcsOutputChannel outputChannel =
GcsServiceFactory.createGcsService().createOrReplace(fileName, GcsFileOptions.getDefaultInstance());
outputChannel.write(ByteBuffer.wrap(byteContent));
outputChannel.close();
尝试这样做,将引发以下异常:
WARNING: Caught IOException while attempting to write blob
java.io.FileNotFoundException: C:\dev\workspace\gaeTestProjekt\war\WEB-INF\appengine-generated\encoded_gs_key:L2dzL015QnVja2V0L2Zvbw (The filename, directory name, or volume label syntax is incorrect)
考虑到目标文件的名称中存在一个额外的冒号(encoded_gs_key:L2dzL015QnVja2V0L2Zvbw),这是有道理的。
问题是,如何防止本地开发服务器尝试创建无效文件名?