Google应用引擎Java - 将CSV导入数据存储区

时间:2014-10-07 18:20:28

标签: java google-app-engine

我正在研究在这个网站上将CSV上传到blobstore,并且只找到了python代码的解决方案,但我需要它用于java应用程序。

我现在就在这里:

步骤1:我将CSV上传到BlobStore,代码为

@SuppressWarnings("serial")
public class ServletBulkUpAgent extends HttpServlet {
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {

        BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
        Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
        BlobKey blobKey = blobs.get("data");

        if (blobKey == null) {
            resp.sendRedirect("/");
        } else {
            resp.sendRedirect("/upload-success?blob-key=" + blobKey.getKeyString());
        }


    }
}

步骤2:只需使用openCSV.jar文件读取CSV文件并打印该值。 这个代码是(这是在成功上传后从上面的代码转移下来的。)

@SuppressWarnings("serial")
public class SuccessfulUploadServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {

        System.out.println("Enter Successful Upload");

        String blobKey = req.getParameter("blob-key");


        BlobstoreInputStream is = new BlobstoreInputStream(new BlobKey(blobKey));

        CSVReader csvReader = new CSVReader(new InputStreamReader(is));
        List<String[]> rows = csvReader.readAll();

        System.out.println(rows);

    }

}

但它引发了以下错误:

  

访问/ _ah / upload / ag1oaWxmZWRlc2tkZW1vciILEhVfX0Jsb2JVcGxvYWRTZXNzaW9uX18YgICAgICAkAgM时出现问题。原因:   Java堆空间

由于我正在寻找一个java解决方案,因此我将回到Python解决方法并不会真正解决这个问题。

0 个答案:

没有答案