How to access a Cloud Storage file from an application running on local

I have only success in writing a file in the Google Storage cloud and reading it. Everything is fine after I deploy the application in appspot, but I got errors when using it locally:

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) ...... 

Do any of you know how to access your Google Cloud Storage file from your local host?

+6
source share
3 answers

The App Engine Developer Testing Environment supports local Google Cloud Storage modeling, but does not provide RPC access to the real thing. Thus, your code should work in both environments, but you should think that the two modes have different namespaces and content. So if, for example, your code expects to see a specific bucket foo containing an object panel, you will want to separately create this file / object and make sure that it contains reasonable content so that the local developer mode works as expected.

+7
source

I managed to find and use the simulated service mentioned above. Unfortunately, for this topic I do not know Java. But this use 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.)

Someone else will have to figure out how to do the same in Java. Sorry.: (

EDIT: Api_server.py is located in the base directory:

 $ python2.7 google_appengine/api_server.py 
0
source

To run it “pseudo” locally (for example, on the command line), you must first deploy it and then use HttpClient to connect to your server. This way you can interact with your / jsp servlet from the command line and not send forms with attachments

Sample code [You can, of course, get more creative than this]

 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 will have the opportunity to call your servlet in a loop, for example, instead of submitting the form several times

-1
source

Source: https://habr.com/ru/post/911004/


All Articles