Reputation: 594
I have just success on writing the file to the Google cloud Storage and reading it. Everything is fine after I deploy the app to appspot, but I got errors when running it local:
INTERNAL_SERVER_ERROR
Caused by:java.io.IOException
at com.google.appengine.api.files.FileServiceImpl.translateException(FileServiceImpl.java:586)
at com.google.appengine.api.files.FileServiceImpl.makeSyncCall(FileServiceImpl.java:561)
......
Does any one of you know how to access Google Cloud Storage file from localhost?
Upvotes: 6
Views: 2668
Reputation: 3570
I was able to find and use the simulated service mentioned above. Unfortunately for this thread, I don't know Java. But it's usage in Python is as follows...
$ python2.7 google_appengine/google/appengine/tools/api_server.py --application myapp
(Note that api_server.py requires Python 2.7 because it depends on the argparse module.)
Somebody else will have to figure out how to do the same in Java. Sorry. :(
EDIT: The api_server.py is in the base directory:
$ python2.7 google_appengine/api_server.py
Upvotes: 0
Reputation: 49
To run it "pseudo" locally (like on a command-line), you should first deploy it and then use HttpClient to connect to your server. That way you can interact with your servlet/jsp from the command line and not have to submit forms with file attachments
Sample code [You can certainly get more creative than that]
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.client.ClientProtocolException;
public class FileUploaderClient {
/**
* @param args
*/
public static void main(String[] args) throws ClientProtocolException, IOException{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://<app-version>.<app-name>.appspot.com/<servlet-name>");
MultipartEntity reqEntity = new MultipartEntity();
FileBody bin = new FileBody(new File("<File you want to upload>"));
reqEntity.addPart("file", bin);
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
System.out.println(response.getStatusLine());
}
}
Now you would have the ability to call your servlet in a loop for example instead of submitting your form multiple times
Upvotes: -1
Reputation: 3808
The App Engine developer test environment supports a local simulation of Google Cloud Storage but doesn't provide RPC access to the real thing. So, your code should work in both environments, but you should think of the two modes as having distinct name spaces and content. So if, for example, your code expects to see a particular bucket foo containing an object bar, you'll want to separately create that bucket/object and ensure it contains reasonable content in order for the local developer mode to work as expected.
Upvotes: 7