gpt4 book ai didi

java - Google App Engine Blobstore 图像

转载 作者:太空宇宙 更新时间:2023-11-04 15:20:26 24 4
gpt4 key购买 nike

我正在尝试创建一个简单的 Web 应用程序来使用 Blobstore 上传多个图像。我已成功将图像上传到 Blobstore。但是,当上传图像时,用于上传的 servlet 不会重定向到我尝试将其重定向到的任何页面。它只是显示一个空白页面,其 URL 如下:myapplicationId.appstore.com/_ah/upload/.…(keyvalue)

我无法更改名为“上传”的 servlet 的重定向到另一个页面。我也尝试提供图像,但无法做到。

有人可以指导我吗?

我正在使用 Java 中的 Google 标准代码来上传图像。

我的 JSP 是:

<%@ page import="com.google.appengine.api.blobstore.BlobstoreServiceFactory" %>
<%@ page import="com.google.appengine.api.blobstore.BlobstoreService" %>
<script>
<%
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();

%>

</script>
<html>
<head>
<title>Show My Picture(s)</title>
</head>
<body>

<h1>Show My Picture(s)</h1>
<hr/>
<h2>Upload picture(s)</h2>
<form action="<%= blobstoreService.createUploadUrl("/upload") %>" method="post" enctype="multipart/form-data">
Upload File(s) :
<input type="text" name="filename"/>
<input type="file" name="myPics" multiple="multiple"/>
<input type="submit" value="Upload Picture"/>
</form>
</html>

我的上传 Servlet:

package photos;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.Map;
import java.util.logging.Logger;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import photos.Upload;

import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.api.blobstore.BlobstoreService;
import com.google.appengine.api.blobstore.BlobstoreServiceFactory;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.images.ImagesService;
import com.google.appengine.api.images.ImagesServiceFactory;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

/**
* Servlet implementation class Upload
*/
@WebServlet("/Upload")
public class Upload extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
private final static Logger _logger = Logger.getLogger(Upload.class.getName());
private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

try{
Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
BlobKey blobKey = blobs.get("myPics");


if (blobKey == null) {
res.sendRedirect("/");
}
else {
res.sendRedirect("/upload?blob-key="+blobKey.getKeyString()+"blobSize="+blobs.size());
}
}catch(Exception e){
e.printStackTrace();
System.out.println("Document failed to POST, redirecting back to upload.");
res.sendRedirect("/index.jsp");
}
}

public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {

String uploadedImageKey = req.getParameter("blob-key");
PrintWriter out = resp.getWriter();
resp.setHeader("Content-Type", "text/html");
resp.sendRedirect("/viewPics.jsp");
//out.println(req.getParameter("blobSize")+" images have been successfully uploaded");



}
}

我哪里出错了?

最佳答案

我想自助是最好的帮助。我解决了这个问题。它只是将 createUploadUrl 中的上传更改为 Upload。

关于java - Google App Engine Blobstore 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20450086/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com