我有一个应用引擎项目,用于通过Blobstore API将文件从我的Android设备上传到Google云端存储。
public class BlobUrlGet extends HttpServlet {
BlobstoreService blServ = BlobstoreServiceFactory.getBlobstoreService();
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
UploadOptions uploadOptions = UploadOptions.Builder.withGoogleStorageBucketName("abc123-974.appspot.com");
String blobUploadUrl = blServ.createUploadUrl("/on_upload_success", uploadOptions);
resp.setStatus(HttpServletResponse.SC_OK);
resp.setContentType("text/plain");
PrintWriter out = resp.getWriter();
out.print(blobUploadUrl);
}
}
当我启动云存储控制台时,上传的文件会显示一个冗长的名称,我假设它只是一个云存储密钥。
是否有任何Cloud Storage API或Blobstore中的方法允许您在上传期间设置文件名?如果不是这样做通常如何?
答案 0 :(得分:0)
我不知道如何从Blobstore Api自定义blob名称,但使用Cloud Storage API,您可以执行以下操作:
GcsFilename gcsFileName = new GcsFilename(bucketName, fileName)
GcsOutputChannel outputChannel = GcsServiceFactory.createGcsService().createOrReplace(
gcsFileName,
new GcsFileOptions.Builder().acl("project-private").build()
);
OutputStream outputStream = new BufferedOutputStream(Channels.newOutputStream(outputChannel));