Hi,

Need some help in uploading a file from Widows Mobile 6.5 device to
GAE blobstore


In the GAE server, I have the following python code; (Its still
crude.. )

class GetNewUploadUrlHandler(webapp.RequestHandler):
    def get(self):
        upload_url = blobstore.create_upload_url('/upload')
        self.response.headers['Content-Type'] = "text/plain"
        self.response.out.write("%s" % upload_url)
        logging.info("\n\n from hgetuploadurl - %s",upload_url)


class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
    def post(self):
        upload_files = self.get_uploads('file')
        for ufile in upload_files:
            blob_info = ufile
            logging.info("key = %s",blob_info.key())
        #
        blob_reader = blobstore.BlobReader(upload_files[0].key())
        # Further processing of the file


In the device we have some C# code to test the implementation, which
uploads a jpg file

        private void button1_Click(object sender, EventArgs e)
        {
            String WebUrl = "http://xxxserver.appspot.com/
getnewuploadurl";  //xxx is a dummy name not the real one

            HttpWebRequest httpRequest =
(HttpWebRequest)HttpWebRequest.Create(WebUrl);
            httpRequest.Timeout = 15000;
            httpRequest.ReadWriteTimeout = 20000;

            using (HttpWebResponse httpResponse =
(HttpWebResponse)httpRequest.GetResponse())
            {
                Encoding enc = System.Text.Encoding.GetEncoding(1252);
                StreamReader loResponseStream = new
StreamReader(httpResponse.GetResponseStream(), enc);
                string Response = loResponseStream.ReadToEnd();

                MessageBox.Show(Response, this.Text,
MessageBoxButtons.OK,
                   MessageBoxIcon.Hand,
MessageBoxDefaultButton.Button1);
                {
                    HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(Response);
                    req.Credentials =
CredentialCache.DefaultCredentials;
                    string boundary = "frontier";
                    req.Method = "POST";

                    req.ContentType = string.Format("multipart/form-
data; boundary={0}", boundary);

                    req.AllowWriteStreamBuffering = true;

                    // Retrieve request stream
                    Stream reqStream = req.GetRequestStream();

                    string imageType = "image/jpeg";
                    string fileName = "test.jpg";
                    string header = string.Format("--{0}", boundary);
                    string footer = string.Format("--{0}--",
boundary);
                    string NewLine = "\r\n";

                    String payload1 = string.Format("{0}{1}Content-
Disposition: file; name=\"file\"; filename=\"{2}\"{1}", header,
NewLine, fileName);
                    String payload2=string.Format("Content-Type: {0}{1}
{1}", imageType, NewLine);

                    String payload = string.Concat(payload1,
payload2);

                    byte[] HeadData =
Encoding.GetEncoding("utf-8").GetBytes(payload.ToString());

                    reqStream.Write(HeadData, 0, HeadData.Length);

                    // Open the local file
                    String path =
System.IO.Path.GetDirectoryName(this.GetType().Assembly.GetModules()
[0].FullyQualifiedName) + "\\test.jpg";
                    FileStream rdr = new FileStream(path,
FileMode.Open);

                    // Allocate byte buffer to hold file contents
                    byte[] inData = new byte[4096];

                    // loop through the local file reading each data
block
                    //  and writing to the request stream buffer
                    int bytesRead = rdr.Read(inData, 0,
inData.Length);
                    while (bytesRead > 0)
                    {
                        reqStream.Write(inData, 0, bytesRead);
                        bytesRead = rdr.Read(inData, 0,
inData.Length);
                    }

                    byte[] FootData =
Encoding.GetEncoding("utf-8").GetBytes(footer.ToString());
                    reqStream.Write(FootData, 0, FootData.Length);

                    rdr.Close();
                    reqStream.Close();

                    req.GetResponse();

                };
            };
        }


Problem:
When I tested the server and the C# client in the device using the GAE
development server; it worked fine.
However after I uploaded the server to the Appspot.com,
req.GetResponse(); fails with error code 503 (Service not available)

Only difference I see between running GAE development server and the
Server in appspot.com is the size and structure of the upload url
generated by the GAE blobstore

eg: with appspot.com url generated is
http://xxxserver.appspot.com/_ah/upload/AMmfu6aEjWpmkRhysTsf8LeZPGjOUB_G2GScVr43zcsShpwHwSiglMCLVyXlr2kl0pDmb4wKwJwub1hk9pTRhenib0fs98IMILBGo_bTdh4gN8DjgHhIwOk/ALBNUaYAAAAATdDYcj3Cgn0TJoqquBKVL9Y2jDmL0Jyg/

Where as with the development server, it is much smaller.

in the appspot logs, we dont see any trace of the UploadHandler
getting called. We feel, the log URL is somehow gets cut and hence
does not get called properly.

Any help to solve/debug this will be much appreciated

Thanks

Chimbu





-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to