【问题标题】:Setting file name during upload to Cloud Storage在上传到 Cloud Storage 期间设置文件名
【发布时间】:2015-09-17 15:29:15
【问题描述】:

我有一个应用引擎项目,用于通过 Blobstore API 将文件从我的 android 设备上传到 Google Cloud Storage。

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 控制台时,上传的文件会出现一个冗长的名称,我假设它只是一个 Cloud Storage 密钥。

是否有任何 Cloud Storage API 或 Blobstore 中允许您在上传期间设置文件名的方法?如果不是,这通常是如何完成的?

【问题讨论】:

    标签: java android google-app-engine google-cloud-storage blobstore


    【解决方案1】:

    我不知道从 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));
    

    【讨论】:

      猜你喜欢
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 2019-04-08
      • 1970-01-01
      • 2018-12-23
      • 1970-01-01
      • 2014-01-05
      • 2016-12-01
      相关资源
      最近更新 更多