i have a servlet in which i try to upload an image. i have pasted my
servlet class here, that gets called from a jsp.
<form action="/testuploadmimevalidation?provider-key=testprovider"
method="post" enctype="multipart/form-data" >


public class TestUploadMimeValidation extends HttpServlet {
    private BlobstoreService blobstoreService =
BlobstoreServiceFactory.getBlobstoreService();
        private static final Logger log =
              Logger.getLogger(TestUploadMimeValidation.class.getName());

        private static final boolean PRODUCTION_MODE =
SystemProperty.environment.value() ==
SystemProperty.Environment.Value.Production;

        private static final String URL_PREFIX = PRODUCTION_MODE ? "" :
"http://127.0.0.1:8080";;

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

    InputStream in = req.getInputStream();
        int formDataLength = req.getContentLength();

      byte dataBytes[] = new byte[formDataLength];
      int len;
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      while ((len = in.read(dataBytes, 0, formDataLength)) != -1)
        bos.write(dataBytes, 0, len);
      dataBytes = bos.toByteArray();

        String urlStr = URL_PREFIX
+BlobstoreServiceFactory.getBlobstoreService().createUploadUrl("/
testupload");

           URLFetchService urlFetch =
URLFetchServiceFactory.getURLFetchService();
           HTTPRequest request = new HTTPRequest(new URL(urlStr),
HTTPMethod.POST, FetchOptions.Builder.withDeadline(10.0));

           request.setHeader(new HTTPHeader("Content-Type","multipart/
form-data"));
           ByteArrayOutputStream baos = new ByteArrayOutputStream();

           request.setPayload(dataBytes);
           try {
               urlFetch.fetch(request);
           } catch (IOException e) {
               // Need a better way of handling Timeout exceptions
here - 10 second deadline
               //log.error("Possible timeout?",e);
           }
            }
    }

the image loads fine into the Blobstore but i get a
NullpointerException. i've read that a DoGet and a DoPost is required
in the target servlet class ("/testupload"): http://jeremyblythe.blogspot.com/
I have implemented those but i keep getting the exception. am I not
supplying enough parameters to the request object? there aren't many
examples online where the blob is uploaded through a servlet by using
the urlfetch.Fetch().

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to