I'm developing a web service in App Engine standard environment with Java (servlets).
The idea is that it get info. from Cloud SQL and generate a EPUB programmatically with Siegmann' epub library: http://www.siegmann.nl/epublib
But i'm not sure that how can add things like images or html files (i first will convert the info. from Cloud SQL to HTML), sicen the writer of epub needs a path to a files.
can i download first all resources that need in local directory of app engine and references them?
Or what can i do?
Thank you in advance and sorry for my English.
Option 1:
You can use the /tmp directory of your App Engine instance to store temporary files. See this link.
Bear in mind that files stored in the /tmp folder will only be accessible within the instance that wrote them.
Option 2:
After a quick look to Siegmann' epub library, I have seen that resources can be provided as Byte arrays and the writer fills an OutputStream.
With this in mind, you could use Cloud Storage and it's Java Client Library to download and store the files.
In this Java sample from the docs, you can see that an object is up laded without the need of it being stored in file-system, just passing it as Byte array.
And to download files from Cloud Storage into the memory of your App Engine App, you could use storage.get(BlobId.of(bucketName, objectName)).getContent() to get the object's byte array
Related
To verify the ownership of a domain to a mail service, I need to put a file with a specific name for verification. Is there a better way than pushing it into my app source repository?
For security reasons you would have to put the file in your source and do a deployment to App Engine. If you’ve worked with a traditional web server in the past where you basically dump files into a folder and serve them this will be a bit of a change. The App Engine files are going to execute only. If you want to get in to adding other files on the fly you would need a Cloud Storage Bucket, but I don’t think that will do it for your domain verification.
I managed to get the "Quickstart for Python 3 in the App Engine Standard Environment" example up and running, and I thought I'd try and further my knowledge a little, perhaps by attempting to get a cron job running.
So I updated the python code, adding another endpoint, counter, like this:
#app.route('/counter')
def counter():
with open('counter.txt', 'a') as the_file:
the_file.write('Hello\n')
return 'Counter incremented'
I intend to have the cron job periodically hit /counter. When this endpoint is hit it will open the file and add a line to it. The /counter endpoint works on my local machine. After I deploy this updated code to the Google cloud, if I go to my blahblah.appspot.com/counter url it should update this 'counter.txt' file.
My question is: How do I see that file to know if it is being updated or not? How do I view that file in the cloud? Thanks.
It not possible to write files in the Google App Engine Standard Python3 environment except in the /tmp directory. As stated in the Python3 GAE official documentation:
The runtime includes a full filesystem. The filesystem is read-only except for the location /tmp, which is a virtual disk storing data in your App Engine instance's RAM.
I agree with #Josh J answer, you should use Google Cloud Storage instead.
You shouldn't write to the local file system in Google App Engine. It may or may not be visible to your app when it scales.
Google Cloud Storage is the preferred method of file storage.
https://cloud.google.com/appengine/docs/standard/python3/using-cloud-storage
For python 2.7 you can import a module from string instead of file, you can see in this answer:
https://stackoverflow.com/a/7548190/8244338
I am trying to upload the file into google app engine from where I would like to retrieve it and then perform conversion into a pdf file. I want to have a cloud access so I am deploying this project. But I dont the best way to go about it. Can anyone help please ? Or is there any solution to directly convert the file while being on the server ?
I don't think there are any ways to convert a file directly on the server. But to store and retrieve, you might want to take a look into the Google Cloud Storage client library (and the one from Python, if needed).
These might help as well (Java and Python). From there you can easily save a file, then retrieve it. Once you retrieve it, do your conversion to pdf and voila!
In my GWT application, a 'root' user upload a specific text file with data and that data should be available to anyone who have access to the app (using GAE).
What's the classic way to store a data that will be available to all users? I don't want to use any database (objectify!?) since this is a relatively small amount of information and it changes from time to time by root.
I was wondering if there was such static MAP on the 'engine level' (not user's session) that this info can be stored (and if the server is down - no bigi, root will upload again)
Thanks
You have three primary options:
Add this file to your /war/ directory and deploy with the app. This is what we typically do with all static files that rarely change (like .css file, images, etc.) This file will be available to all users, whether they are authenticated or not.
Add this file to your /war/WEB-INF/ directory and deploy with the app. This file will be available to your server-side code, so you can read it on the server-side and show to a user. This way you can decide which users can see this file and which users should not have access to it.
Upload this file to Google Cloud Storage. You can do it through an app, or you can simply upload it manually to a bucket using a GCS console or gsutil command-line tool. Then you simply provide a link to your users. The advantage of this option is that you do not have to redeploy your app when a file changes.
The only reason to go with the first two options is to have this file under version control. If you don't need that, I would recommend going with the GCS option.
Can I download my App Engine source code from Google?
Update: Google appengine now allows you to download the code
Documentation here.
(Duplicating answer from the duplicate thread)
You can't - App Engine is not a source control system. There are handlers available that will let you download your source code directly, if you set them in app.yaml when you uploaded your app. They can't include files marked static, however, since they are uploaded to a separate location.
Probably not. However, you can create a wrapper script around appcfg.py which will archive your source code and upload it along with everything else, then make that archive available on a protected part of the site.
An example of that is here.