简体   繁体   中英

How to export queried data from Google Cloud Datastore to csv using Java?

I have a use case where I need to perform the querying operation on the data stored in Google Cloud Datastore and display the results and provide a download link to the csv file of the same data.

I had gone through different documentations, but it dealt mostly with python whereas my implementation is in Java.

Please guide.

Here is one possible way: you build your csv file in memory in a Cloud Endpoint by querying the Cloud datastore and print to a ByteArrayOutputStream, as shown hereafter:

ByteArrayOutputStream csvOS = new ByteArrayOutputStream();
PrintStream printer = new PrintStream(csvOS);
printer.println("L1C1;L1C2;L1C3");
printer.println("L2C1;L2C2;L2C3");
printer.close();

Then you save the csv file to Cloud Storage and return the URL for downloading it, as I explained in the following answer:

https://stackoverflow.com/a/37603225/3371862

An other possibility would be to stream the result through a Google App Engine servlet (ie you don't go through Cloud Endpoints). Have a look at how to write csv file in google app by using java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM