appcfg.py & .xaml files (silverlight) & mimtype issue

33 views
Skip to first unread message

Neo42

unread,
Nov 7, 2008, 7:41:03 AM11/7/08
to Google App Engine
How do I use the upload tool (appcfg.py) and my app.yaml file to
upload .XAML (silverlight) files?


Here are the handlers in my yaml:
handlers:
- url: /stylesheets
static_dir: stylesheets

- url: /silverlight
static_dir: silverlight

- url: /.*
script: helloworld.py



My xaml and such is in the silverlight directory. My appcfg.py
command is:
appcfg.py update C:\GoogleAppsProjects\HelloWorld


When I try to do it I get this:
"Could not guess mimetype for silverlight/scene.xaml. Using
application/octet-stream."



And the uploaded xaml file doesn't work. By the way, the localhost
version of the app runs fine. It's the upload tool that is screwing
something up.


I can't figure out how to do it from this page:
http://code.google.com/appengine/docs/configuringanapp.html#Static_File_Handlers



I'm new to python. Please help. I suppose I could try to put my xaml
code in the html code, but I'd prefer not to.

Thanks.

Dan Sanderson

unread,
Nov 7, 2008, 12:22:50 PM11/7/08
to google-a...@googlegroups.com
You can specify the MIME type manually with the mime_type option in app.yaml.  For example:

- url: /silverlight/(.*\.xaml)
  static_files: silverlight/\1
  mime_type: application/xaml+xml

(I didn't test this, so let me know how it goes.  :) )

-- Dan

Marzia Niccolai

unread,
Nov 7, 2008, 12:23:30 PM11/7/08
to google-a...@googlegroups.com
Hi,

Does this work if you add the mime_type argument explicitly to the handle?


- url: /silverlight
  static_dir: silverlight
  mime_type: applicaition/x-silverlight-app

-Marzia

On Fri, Nov 7, 2008 at 4:41 AM, Neo42 <Matri...@gmail.com> wrote:

Neo42

unread,
Nov 7, 2008, 1:54:27 PM11/7/08
to Google App Engine
I got it to work by:

1) Modifying my appcfg.py code. Added a mimetype. Details below.
2) check my html and file names for case (the online google app engine
is case sensitive)

File: C:\google_appengine\google\appengine\tools\appcfg.py
Towards the bottom in function "main" needs to run this line (i made
it the first line):
mimetypes.add_type("application/xaml", ".xaml")

Thanks!



On Nov 7, 7:41 am, Neo42 <MatrixNe...@gmail.com> wrote:
> How do I use the upload tool (appcfg.py) and my app.yaml file to
> upload .XAML (silverlight) files?
>
> Here are the handlers in my yaml:
> handlers:
> - url: /stylesheets
>   static_dir: stylesheets
>
> - url: /silverlight
>   static_dir: silverlight
>
> - url: /.*
>   script: helloworld.py
>
> My xaml and such is in the silverlight directory.  My appcfg.py
> command is:
> appcfg.py  update  C:\GoogleAppsProjects\HelloWorld
>
> When I try to do it I get this:
> "Could not guess mimetype for silverlight/scene.xaml.  Using
> application/octet-stream."
>
> And the uploaded xaml file doesn't work.  By the way, the localhost
> version of the app runs fine.  It's the upload tool that is screwing
> something up.
>
> I can't figure out how to do it from this page:http://code.google.com/appengine/docs/configuringanapp.html#Static_Fi...

Neo42

unread,
Nov 10, 2008, 1:03:29 PM11/10/08
to Google App Engine
Now I also know how to pass values to and return values from the
google app engine datastore:


here's my code:::: - default.html, scene.js , scene.xaml, and
silverlight.js (downloadable from the web) are placed in the subfolder
silverlight. the rest go in the root of the app.


app.yaml:

application: nameofapplicationhere
version: 1
runtime: python
api_version: 1

handlers:
- url: /stylesheets
static_dir: stylesheets

- url: /silverlight
static_dir: silverlight


- url: /.*
script: helloworld.py



helloworld.py:

import cgi

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
#from django.conf.urls.defaults import *

import os
from google.appengine.ext.webapp import template

class Greeting(db.Model):
author = db.UserProperty()
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)
entryid = db.IntegerProperty()


class MainPage(webapp.RequestHandler):
def get(self):
greetings_query = Greeting.all().order('-date')
greetings = greetings_query.fetch(10)

if users.get_current_user():
url = users.create_logout_url(self.request.uri)
url_linktext = 'Logout'
else:
url = users.create_login_url(self.request.uri)
url_linktext = 'Login'

template_values = {
'greetings': greetings,
'url': url,
'url_linktext': url_linktext,
}

path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))


class Guestbook(webapp.RequestHandler):
def post(self):
greeting = Greeting()

if users.get_current_user():
greeting.author = users.get_current_user()

greeting.content = self.request.get('content')
greeting.entryid = eval( self.request.get('entryid') )
greeting.put()

self.redirect('/')


class funcGetDataTest(webapp.RequestHandler):
def get(self):

greetings_query = Greeting.all().order('-date')
greetings = greetings_query.fetch(10)

if users.get_current_user():
url = users.create_logout_url(self.request.uri)
url_linktext = 'Logout'
else:
url = users.create_login_url(self.request.uri)
url_linktext = 'Login'

template_values = {
'greetings': greetings,
'url': url,
'url_linktext': url_linktext,
}

path = os.path.join(os.path.dirname(__file__), 'getDataTest.html')
self.response.out.write(template.render(path, template_values))


class paramtest(webapp.RequestHandler):
def get(self ):

greetings_query = db.GqlQuery("select * from Greeting where
entryid=:1 order by date desc",
eval(self.request.get('entryid')) )
greetings = greetings_query.fetch( 1 )

greetingsmore_query = db.GqlQuery("select * from GreetingMore
where entryid=:1 order by date desc",
eval(self.request.get('entryid')) )
greetingsmore = greetingsmore_query.fetch( 1 )

if users.get_current_user():
url = users.create_logout_url(self.request.uri)
url_linktext = 'Logout'
else:
url = users.create_login_url(self.request.uri)
url_linktext = 'Login'

template_values = {
'greetings': greetings,
'url': url,
'url_linktext': url_linktext,
}

path = os.path.join(os.path.dirname(__file__), 'getDataTest.html')
self.response.out.write(template.render(path, template_values))




###########################################################

application = webapp.WSGIApplication(
[('/', MainPage),
('/sign', Guestbook),
(r'/paramtest', paramtest),
('/getdatatest',
funcGetDataTest)
],
debug=True)

def main():
run_wsgi_app(application)

if __name__ == "__main__":
main()



getdatatest.html:


<rwrecord>
{% for greeting in greetings %}
{% if greeting.author %}
<fname>{{greeting.author.nickname}}</fname>
<lname>{{greeting.author.nickname}}</lname>
{% else %}
<fname>anonymous</fname>
<lname>anonymous</lname>
{% endif %}
<id>{{ greeting.content|escape }}</id>
<entryid>{{ greeting.entryid }}</entryid>
{% endfor %}
</rwrecord>



scene.js:

var xmlhttp;
var senderobject; //senderobject.findname("objectName");



function setSenderObject(sender, eventargs) {
senderobject = sender;
}


function loadXMLDoc(url) {
var ms = new Date().getTime().toString();
var seed = "&timestamp=" + ms; //its caching junk - using this to
make the url passed to the app engine always unique
url = url + seed;

//alert(url);
xmlhttp = null;
if (window.XMLHttpRequest) {// code for IE7, Firefox, Opera, etc.
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject) {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

if (xmlhttp != null) {
xmlhttp.onreadystatechange = state_Change;
xmlhttp.open("GET", url, true);
xmlhttp.send(null);
}
else {
alert("Your browser does not support XMLHTTP.");
}
}

function loadXMLDoc3(sender, eventargs) {
setSenderObject(sender, eventargs);
loadXMLDoc('../paramtest?entryid=4'); //paramtest.asp?recordid=1
}

function loadXMLDoc2(sender, eventargs) {
setSenderObject(sender, eventargs);
loadXMLDoc('../paramtest?entryid=5'); //dbrwtest.asp');
}

function loadXMLDoc1(sender, eventargs) {
setSenderObject(sender, eventargs);
loadXMLDoc('../getdatatest?noval=0'); // http://localhost:8080/
}



scene.xaml:



<Canvas xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">


<!-- <Canvas.Resources>
<Storyboard x:Name="mouseEnter">
<ColorAnimation Duration="00:00:00.25" To="#3DFFFFFF"
Storyboard.TargetName="highlightEllipse"
Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" />
</Storyboard>
<Storyboard x:Name="mouseDown">
<ColorAnimation Duration="00:00:00.2" To="#22000000"
Storyboard.TargetName="highlightEllipse"
Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" />
</Storyboard>
<Storyboard x:Name="mouseUp">
<ColorAnimation Duration="00:00:00.2" To="#3DFFFFFF"
Storyboard.TargetName="highlightEllipse"
Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" />
</Storyboard>
<Storyboard x:Name="mouseLeave">
<ColorAnimation Duration="00:00:00.25" To="#00FFFFFF"
Storyboard.TargetName="highlightEllipse"
Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" />
</Storyboard>
</Canvas.Resources>-->


<Canvas Width="120" Height="44">
<Rectangle StrokeThickness="4" RadiusX="17" RadiusY="36"
Width="120" Height="44" Stroke="#46000000">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,-0.409"
StartPoint="0.5,1.409">
<GradientStop Color="gray" Offset="0.242"/>
<GradientStop Color="black" Offset="0.333"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock Width="67" Height="23.2" Canvas.Left="29"
Canvas.Top="10" Foreground="#FFEFEFEF" Text="Click Me"
MouseLeftButtonDown="testxmlcodegen" />
<Rectangle StrokeThickness="4" RadiusX="16" RadiusY="36"
Width="104" Height="32" Canvas.Left="8" Canvas.Top="1.3">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,-0.409"
StartPoint="0.5,1.409">
<GradientStop Color="#00FFFFFF" Offset="0.13"/>
<GradientStop Color="#FFFFFFFF" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle MouseLeftButtonDown="testxmlcodegen" RadiusX="17"
RadiusY="36" Width="114" Height="38" Fill="#00FFFFFF"
x:Name="highlightEllipse" Canvas.Left="3" Canvas.Top="3"/>




<TextBlock FontSize="50" Canvas.Left="200" x:Name="tbheader"
Width="240"
FontFamily="Times New Roman" Visibility="Collapsed">
<Run Text="Using the HttpRequest Object"/>
</TextBlock>


<Canvas x:Name="rlboard" Canvas.Left='100' Canvas.Top='250'/>


<TextBlock FontSize="50" Canvas.Left="527.347" Canvas.Top="240"
x:Name="tbbutton1"
Foreground="Brown" MouseLeftButtonDown="loadXMLDoc1"
Cursor="Hand" FontFamily="Times New Roman">
<!--MouseEnter="mouseoverhighlight"
MouseLeave="mouseoverUNhighlight"-->
<Run Text="1 Read Test"/>
</TextBlock>

<TextBlock FontSize="50" Canvas.Left="427.347" Canvas.Top="200"
x:Name="tbbutton2"
Foreground="Brown" MouseLeftButtonDown="loadXMLDoc2"
Cursor="Hand" FontFamily="Times New Roman">
<!--MouseEnter="mouseoverhighlight"
MouseLeave="mouseoverUNhighlight"-->
<Run Text="2 rw test"/>
</TextBlock>

<TextBlock FontSize="50" Canvas.Left="327.347" Canvas.Top="160"
x:Name="tbbutton3"
Foreground="Brown" MouseLeftButtonDown="loadXMLDoc3"
Cursor="Hand" FontFamily="Times New Roman">
<!--MouseEnter="mouseoverhighlight"
MouseLeave="mouseoverUNhighlight"-->
<Run Text="3 param test"/>
</TextBlock>


<TextBlock FontSize="50" Canvas.Left="127.347" Canvas.Top="270"
x:Name="tbstatus"
Foreground="Black" FontFamily="Times New Roman">
<Run Text=""/>
</TextBlock>

<TextBlock FontSize="50" Canvas.Left="227.347" Canvas.Top="270"
x:Name="tbstatustext"
Foreground="Black" FontFamily="Times New Roman">
<Run Text=""/>
</TextBlock>

<TextBlock FontSize="50" Canvas.Left="327.347" Canvas.Top="270"
x:Name="tbresponse"
Foreground="Black" FontFamily="Times New Roman">
<Run Text=""/>
</TextBlock>


<!--<p>
<b>Status:</b>
<span id="A1"></span>
</p>

<p>
<b>Status text:</b>
<span id="A2"></span>
</p>

<p>
<b>Response:</b>
<br />
<span id="A3"></span>
</p>-->


<!--<Ellipse
Height="200" Width="200"
Stroke="Black" StrokeThickness="10" Fill="SlateBlue" />-->

</Canvas>
</Canvas>


default.html:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ScriptWeb1</title>
<script type="text/javascript" src="silverlight.js"></script>
<script type="text/javascript" src="scene.js"></script>
<!--- <script type="text/javascript" src="gears_init.js"></
script> -->
<style type="text/css">
#errorLocation {
font-size: small;
color: Gray;
}
#silverlightControlHost {
height: 480px;
width: 640px;
}

</style>
</head>

<body>
<!-- Runtime errors from Silverlight will be displayed here.
This will contain debugging information and should be removed or
hidden when debugging is completed -->
<div id='errorLocation'></div>

<div id="silverlightPlugInHost">
<script type="text/javascript">
// var request = google.gears.factory.create('beta.httprequest');
// request.open('GET', 'http://matrixneo42.brinkster.net/
testx.htm');
// //'http://spreadsheets.google.com/feeds/list/
o09771196949220461566.8140527497938195002/default/public/
basic'); //'http://blogs.msdn.com/sburke/atom.xml'); //'/
index.html');
// request.onreadystatechange = function() {
// if (request.readyState == 4) {
// console.write(request.responseText);
// }
// };
// request.send();


if (!window.Silverlight)
window.Silverlight = {};

Silverlight.createDelegate = function(instance, method) {
return function() {
return method.apply(instance, arguments);
}
}

//var scene = new ScriptWeb1.Scene();

Silverlight.createObjectEx({
source: 'scene.xaml',
parentElement:
document.getElementById('silverlightPlugInHost'),
id: 'silverlightPlugIn',
properties: {
width: '100%',
height: '100%',
background:'white',
version: '2.0.31005.0'
},
events: {
onLoad: null, //Silverlight.createDelegate(scene,
scene.handleLoad)
onError: function(sender, args) {
var errorDiv = document.getElementById("errorLocation");
if (errorDiv != null) {
var errorText = args.errorType + "- " +
args.errorMessage;

if (args.ErrorType == "ParserError") {
errorText += "<br>File: " + args.xamlFile;
errorText += ", line " + args.lineNumber;
errorText += " character " + args.charPosition;
}
else if (args.ErrorType == "RuntimeError") {
errorText += "<br>line " + args.lineNumber;
errorText += " character " + args.charPosition;
}
errorDiv.innerHTML = errorText;
}
}
},
context: null
});
</script>
</div>
</body>
</html>



Reply all
Reply to author
Forward
0 new messages