GWT Blobstore error calling createUploadUrl()

主宰稳场 提交于 2019-11-29 10:08:11

I found my own error! as it turn out the reason this was suddenly failing was because the FORM post thought it was cross domain posting. I was testing the web site by calling 127.0.0.1:8888..etc but when the when my Image RPC was called to establish the upload path, it returned to the form setAction the my machine name kmoore-PC:8888..etc instead of the 127.0.0.1:8888... and hence it returned null because it thought it was crossing domains.

To fix, click on the google box in url bar and add your computer name and then test you app using the computer name instead of 127

I tried replacing local host with machine name it didn't help, but it is a cross domain java-script issue so I tried just using the URL pattern assigned in the web xml and I got a String result. The result is my response wrapped with XML and I plan to parse it. if any one has something more elegant please tell me.

here is the response String [it looks a bit different because it affects the stack overflow page]:

pre style="word-wrap: break-word; white-space: pre-wrap;">my response id

Here is the relevant server code

public void doPost(HttpServletRequest request, HttpServletResponse response) throws >ServletException, IOException { //Redirect recursively to this servlet (calls doGet) response.sendRedirect("/blobstoreexample/uploadservice?id=" + >item_image_blob_key); } }

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException 
{
    System.out.println("shonka");
  //Send the meta-data id back to the client in the HttpServletResponse response
  String id = req.getParameter("id");

  response.getWriter().write(id);
  return;

}

Here is the relevant client code, no need for parsing here is the server side code:

uploadForm.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
      @Override
      public void onSubmitComplete(SubmitCompleteEvent event) {

        //The submit complete Event Results will contain the unique
        //identifier for the picture's meta-data.  Trim it to remove
        //trailing spaces and line breaks
          System.out.println("uploadForm onSubmitComplete() results are: " + event.getResults());

          Window.alert(event.getResults());
          if(event.getResults() != null)
          {
             // getPicture(event.getResults().trim());
          }
          else
          {
              Window.alert(event.getResults());
          }

      }

    });

Edit I found a more elegant way to deliver a long id

//Redirect recursively to this servlet (calls doGet)
        response.sendRedirect("/itemmanager/receive?id=" + item.getKey().getId());
      }

      @Override
      protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException 
      {
          System.out.println("entered do post");
        //Send the meta-data id back to the client in the HttpServletResponse response
        String id = req.getParameter("id");
        System.out.println("entered do post id is: " + id);
        resp.setHeader("Content-Type", "text/html");
        resp.getWriter().println(id);

      }

Instead of using the computer name, I simply replace it with the 127 address when in dev mode, like so:

String url = blobstoreService.createUploadUrl("/project/uploadservice");

// change the computer name to standard localhost ip address, if in dev mode
if(SystemProperty.environment.value() == SystemProperty.Environment.Value.Development)
{
    url = url.replace("Your-PC-Name", "127.0.0.1");
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!