How to deploy images on Google App Engine? - google-app-engine

How can I deploy images to Google App Engine?
My image is in the directory /css/images/error1.png
But on appspot.com: "The requested URL /css/images/error1.png was not found on this server."
What is wrong?
The upload-log: http://pastebin.com/VAK5hYPC

Have you mapped the directory as a static directory in your app.yaml file?

Try this and type in the url path in your browser to see if the image is found (Might even be a typo somewere)
- url: /css
static_dir: static/css/images

Related

Django on Google app engine cannot serve media files

I deployed a Django web app on Google app engine flex env, and I could upload files to this app, but the MEDIA_URL and MEDIA_ROOT are not set to Google cloud storage for now, so uploaded files should be stored on local disk.
The problem is, when I open the app website, some uploaded images cannot load successfully, with error saying
GET https://app-name.ew.r.appspot.com/media/images/icon_TPUrf8a.jpg 404
and strangely, even the same image could some time load and then sometime cannot load, very random.
Could anyone please tell why it sometimes ok and sometime not, and what's the best way to fix it?
You have to tell the app where to look for your static files. This is best done in app.yaml:
handlers:
- url: /static
static_dir: static/
- url: .*
script: auto

php script for upload image not working for app engine

I have a folder called "test-my-app1" that includes my app for the google's app engine. This folder has a folder inside called img that stores all of my images for the CSS of my app, and also has a folder named profile. In the folder called profile ( test-my-app1/img/profile/ ) the user can upload a photo for his profile picture.
The php script that I use works successfully for the XAMPP that I have in my laptop. The problem is that when I run the script in app engine, image is not uploaded into my folder "profile". This is my app yaml file:
application: test-my-app1
version: 1
runtime: php
api_version: 1
handlers:
- url: /img
static_dir: img
- url: /profile/(.*\.(gif|png|jpg))
static_files: profile/\1
upload: profile/(.*\.(gif|png|jpg))
any idea how to fix it? there is a possible answer here : App Engine PHP upload file for my question but did not solved my problem
You need to upload files to Google Cloud Storage, the instructions on how to do this are here.
Once the files have been uploaded to Google Cloud Storage you can serve them in HTTP responses, follow the instructions here on using the Image serving service that allows for on the fly resizing, cropping and rotation.
You need to consider the filesystem where your application files are uploaded to as read only.

Images not loading in site hosted on Google App Engine

I am trying to host my site on Google APP Engine. I have configured my app.yaml file and deployed the website. All the files deployed correctly including the css and js files. What I am facing trouble with are the image files. I am getting a 404 resource not found error in my console for the images that my static web page is using. I am not sure what the problem is. Here is the structure of my site
index.html
view(folder)
-images
-abc.png
-xyz.png
-js
-css
Here is the code in app.yaml
- url: /(.*\.png)
mime_type: image/png
static_files: template/\1
upload: template/(.*\.png)
Wanted to know if the app.yaml is configured correctly to go through the images folder and then upload my image files.
You are pointing to the template directory in app.yaml, but you images are actually in a directory tree branched as view/images. Try this:
- url: /(.*\.png)
mime_type: image/png
static_files: view/images/\1
upload: view/images/(.*\.png)

Google App Engine - set index/home page

from what I understand, the app.yaml file in a Google App Engine project, can serve a file as a 'home' page. When I navigate to my domain, however, it always gives me a 404. My app.yaml is in the war directory. This is what my app.yaml looks like:
application: therealtest
version: 10
runtime: python
api_version: 1
handlers:
- url: /
static_files: site/index-static.html
upload: site/index-static\.html
What I am expecting it to do is to display the page index-static.html when I go to the domain of the site, but it does not. Is this not the correct way to do this? Thank you.
Is the site directory inside your war directory? It should be, given that is where you said your app.yaml file is.
FWIW, putting your web app in a war directory implies to me that you're thinking in Java terms, but your app.yaml snippet tells us you're using Python. In Java, WAR stands for Web Archive, which is a zip file with a certain required directories and files.

Uploading images along with Google App Engine

I'm working on a Google App Engine project.
My app is working and looking correct locally, but when I try to upload images in an image directory, they're not being displayed at appspot.
As a little troubleshoot, I put a HTML page in "/images/page2.html" and I can load that page at the appspot, but my pages don't display my images. So, it's not a problem with my path.
As another sanity check, I'm also uploading a style sheet directory with .css code in it, and that's being read properly.
I have a suspicion that the problem lies in my app.yaml file.
Any ideas?
I don't want to paste all the code here, but here are some of the key lines. The first two work fine. The third does not work:
<link type="text/css" rel="stylesheet" href="/stylesheets/style.css" />
Page 2
<img src="/images/img.gif">
This is my app.yaml file
application: myApp
version: 1
runtime: python
api_version: 1
handlers:
- url: /stylesheets
static_dir: stylesheets
- url: /images
static_dir: images
- url: /.*
script: helloworld.py
You have to configure app.yaml for static content such as images and css files
Example:
url: /(.*\.(gif|png|jpg))
static_files: static/\1
upload: static/(.*\.(gif|png|jpg))
For more info check out:
http://code.google.com/appengine/docs/configuringanapp.html
I'll bet your problem is that you're using Windows.
If that's the case, I believe you need a preceding slash for your static_dir value.
I am using the Java version of App engine, and I faced a similar issues with the server not able to serve static images.
What worked ultimately was to change the AppEngine config file "appengine-web.xml" in my case to contain
<static-files>
<include path="**.*"/>
<include path="/images/**.*" />
</static-files>
My images are in the /images directory and HTML and CSS are in . directory which is at the WEB-INF level
#jamtoday The preceding slash didn't make a difference, but it did get me started figuring out what each app needs to be told what about my directory structure.
So, I have nothing very conclusive to add, but I wanted to follow up, because I got it working, but I didn't explore all the issues after I got it working.
One change that helped was to stop working from a HwlloWorld/src/ directory and start working in the HelloWorld/ directory. It seems like the dev_appserver picked up all the dependencies, but the remote server didn't. Essentially, the relative path of my local links didn't match the relative path of the links after uploading.
I also realized that the dev-appserver relies on the .yaml file, as well as the appcfg script. That is. . .if you add a directory to your project, and then try to link to files in that directory, you need to add the directory to the .yaml file, and then restart the dev-appserver to pick up on this.
So, there are probably ways to handle what I was originally trying to do if you give the .yaml file the right info, but changing to a different directory structure locally handled it for me.
<img src="/images/img.gif">
this line can't show you the image.
Try this one:
1-Create a class to handle "image request"
class GetImage(webapp.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'image/jpg'
self.response.out.write(image_object)
2-In your page.html:
<img src="/image"
3-At the main function in your code.py:
application = webapp.WSGIApplication(('/image', GetImage), debug=True)
have fun

Resources