2

我一直在寻找几个星期来找到一个解决方案,该解决方案允许我从已上传到 Google App Engine 的 mp3 文件中读取 id3 标签。上传的文件存储在 Blobstore 中,我正在使用 Java 进行编码。

我想请求帮助完成两项任务:

  1. 我想访问可以从最流行的音频文件格式中读取 id3 信息的库或方法。我已经尝试了一些可以做到这一点的库,但它们都需要访问 GAE 不支持的 java.io.File。因此,必须从内存或其他 GAE 支持的访问方法中读取帧/标签。
  2. 我想知道如何从 doPost 方法中获取字节,而不是再次访问 blobstore。

以下是我希望完成的代码:

protected void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(req);
    List<BlobKey> blobKeys = blobs.get("aud-file");

    BlobKey fileKey = blobKeys.get(0);
    BlobInfo info = blobInfoFactory.loadBlobInfo(fileKey);
    String filename = info.getFilename();
    long size = info.getSize();
    Date created = info.getCreation();
    String key = info.getBlobKey().getKeyString();

    // TODO: Get mp3 file that was just uploaded and retrieve ID3 tag 
    //       info.

    SimpleDateFormat formatter = new SimpleDateFormat();
    formatter.applyPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
    StringBuilder builder = new StringBuilder();
    builder.append("<?xml version=\"1.0\" ?>");
    builder.append("<file name=\"" + filename + "\" ");
    builder.append("size=\"" + Long.toString(size) + "\" ");
    builder.append("created=\"" 
            + formatter.format(created).toString() + "\" ");
    builder.append("key=\"" + key + "\">");

    // TODO: append Title, Artist, and Duration of audio file for 
    //       response to client side code

    builder.append("</file>");

    resp.setStatus(HttpServletResponse.SC_OK);
    resp.setContentType("text/html;charset=\"utf-8\"");
    PrintWriter writer = resp.getWriter();
    writer.write(builder.toString());
    writer.flush();
    writer.close();
}

上面的代码正在运行,对于任何想要从上传的文件中检索信息的人来说,这似乎是一个很好的模式。(如果在 Eclipse 中进行本地测试,请确保将您的 bindAddress 标志设置为本地机器名称,并将该名称作为主机添加到 GWT 开发人员插件选项中。)提前感谢您对此请求的任何帮助。

克里斯

4

3 回答 3

1

您可以尝试使用Jaudiotagger。唯一的问题是它需要一个可读的java.io.File.

要完成这项工作,您可以尝试使用Filewrapper for GAE。一个使用它的例子是here

于 2012-07-30T16:54:27.657 回答
0

Using GAE for storage of any kind of larger files is not such a good idea. According to this wiki article there are hard limits to request/response times and also for the amount of data that can be transferred:

  • Response must return within 60 seconds (assuming you have a large file and slow connection this could be a problem)
  • request can be max 1MB large (not shure of this)
  • response can be max 32 MB large
  • also I think there is a 1MB limit of entry in blob store (so even if you manage to get the file there, you would have to split the file into multiple entries)

i think it would be good if you just make a few tests before doing some real work there.

于 2012-11-27T12:35:56.623 回答
0

使用 blobstore 和 createUploadUrl 上传文件后,数据已经在 blobstore 中,您只能使用 blobstore API 访问它。

于 2012-07-30T16:30:49.453 回答