问题
I am trying to upload a file in GAE using the Blobstore API. I am getting the following exception when running the GAE server locally (dev mode):
WARNING: /_ah/upload/ag10cmlwc2NoZWR1bGVychsLEhVfX0Jsb2JVcGxvYWRTZXNzaW9uX18YFQw
java.lang.IllegalStateException: Must call one of set*BlobStorage() first.
at com.google.appengine.api.blobstore.dev.BlobStorageFactory.getBlobStorage(BlobStorageFactory.java:24)
at com.google.appengine.api.blobstore.dev.UploadBlobServlet.init(UploadBlobServlet.java:88)
at javax.servlet.GenericServlet.init(GenericServlet.java:215)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
I am running GAE 1.3.5 but have tried all versions since GAE 1.3.0 (first version with the Blobstore). I am using the GAE maven plugin: http://code.google.com/p/maven-gae-plugin/
My form is written in GWT 2.0.4. Currently, the form is just a file input field with a submit.
I receive the above exception after submitting the form. I am able to successfully retrieve an upload URL from the Blobstore Service.
Everything works fine on GAE. I have verified that nothing is entered into the blobstore in my local dev env (via the dev admin console). I am uploading a CSV that is ~1Kb but have tried other file types/sizes as well without success (same files work on GAE prod).
回答1:
When call your page that generates html (using servlet, jsp, etc.) and calls blobstoreService.createUploadUrl("/upload");
you can't re-use this page multiple times.
Reload this page in a browser every time you want to upload the file.
回答2:
The issue was caused by having the stubs and testing jars included on the classpath when running the dev app server. If you are using maven, simply change the scope of the dependency:
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>${gae.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-testing</artifactId>
<version>${gae.version}</version>
<scope>test</scope>
</dependency>
If you are not using maven, make sure these jars are not in your WEB-INF/lib or classpath.
回答3:
$ mvn clean gae:run -DskipTest
works for me
回答4:
I am not using Maven, just Eclipse and the GAE plugins. I also didn't see any test.jar files in my classpath. I just deleted the Run Configuration in Eclipse and restarted and it worked. No idea what went wrong, but this fixed the issue for me while running in dev/local mode.
回答5:
If not using maven but Eclipse with plugin:
REMOVE RUN/DEBUG CONFIGURATION. To create new, simply right click on project and select run/debug As > Web Application
来源:https://stackoverflow.com/questions/3402226/gae-java-lang-illegalstateexception-must-call-one-of-setblobstorage-first