Hi,

I think the problem is the body content might be getting mangled. I
was able to hack this together (excuse any butchery of the .NET
framework) and make it work:


            String token = "DQA<snip>1wNajrab_8_YpA";
            String url = "http://docs.google.com/feeds/documents/
private/full";

            HttpWebRequest req = (HttpWebRequest)
WebRequest.Create(url);
            req.Method = "POST";
            req.ContentType = "application/vnd.ms-excel";

            String op = "Authorization: GoogleLogin auth=";
            op += token;
            req.Headers.Add(op);
            req.Headers.Add("Slug: test.xls");

            Stream postBody = req.GetRequestStream();

            FileStream fs = new FileStream("C:\\test.xls",
FileMode.Open);
            byte[] bytes = new byte[1024];
            while (fs.CanRead)
            {
                int read = fs.Read(bytes, 0, 1024);
                postBody.Write(bytes, 0, read);
                if (read == 0)
                {
                    break;
                }
            }
            fs.Close();
            postBody.Close();

            WebResponse result = req.GetResponse();


Hope this helps!

Cheers,
-Jeff

On Oct 22, 8:57 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Thanks for your timely reply, but unfortunately I get the same
> "(500)Internal Server Error" Message after modification of my code to
> like following:
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>                     StreamReader sr1 = new StreamReader("test.xls");
>                     String xlsStrData = sr1.ReadToEnd();
>                     ASCIIEncoding encoding = new ASCIIEncoding();
>                     String postBodyStr = xlsStrData;
>                     byte[] postBodyData =
> encoding.GetBytes(postBodyStr);
>                     HttpWebRequest req =
> (HttpWebRequest)WebRequest.Create(url);
>                     req.Method = "POST";
>                     req.ContentLength = postBodyData.Length;
>                     req.ContentType = "application/vnd.ms-excel";
>
>                     String op = "Authorization: GoogleLogin ";
>                     op += token;
>                     req.Headers.Add(op);
>                     req.Headers.Add("Slug: test.xls");
>
>                     Stream postbody = req.GetRequestStream();
>                     postbody.Write(postBodyData, 0,
> postBodyData.Length);
>                     postbody.Close();
>
>                     WebResponse result = req.GetResponse(); // still
> get the same exception in this statement
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> Any suggestions?
>
> Best Regards
>
> On Oct 23, 5:32 am, "Jeff Fisher (Google)" <[EMAIL PROTECTED]>
> wrote:
>
> > Hi,
>
> > There have been some recent changes to the way the Documents List API
> > handles file uploads. Instead of writing a MIME entry to the server,
> > try just sending the raw bytes of the XLS file and changing the
> > Content-Type of the POST itself to be 'application/vnd.ms-excel'.
> > Whatever is provided in the Slug header will be the title (and it
> > shouldn't have to end in .xls).
>
> > The documentation will be updated soon to reflect this.
>
> > Cheers,
> > -Jeff
>
> > On Oct 22, 3:37 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> > > hi, guys,
> > >   I tried to upload a xls file to google documents from a windows
> > > mobile device, but I always get the following error:
> > > ==> "The remote server returned an error: (500) Internal Server
> > > Error."
>
> > >   I am sure that I get a correct authenticating because I can
> > > sucessfully get the document list. I make the post content identical
> > > to the tutorial.
> > >   I tried the java library, it works great. Then I capture the ip
> > > packet and fill in my post body as it does, still get the 500 error.
> > > the main part of java library sent to upload a new xls looks like
> > > following:
> > > ---------------------------------------------------------------------------
> > >  -----------------------------------------------
> > > <entry xmlns='http://www.w3.org/2005/Atom'>
> > >     <category scheme='http://schemas.google.com/g/2005#kind'
> > >      term='http://schemas.google.com/docs/2007#spreadsheet'
> > > label='spreadsheet'>
> > >    </category>
> > >    <title type='text'>test.xls</title>
> > >    <content type='application/vnd.ms-excel'>
> > >    </content>
> > > </entry>\r\n"
>
> > > while the guide's main part looks like
> > > ---------------------------------------------------------------------------
> > >  ---------------------------------------------------
> > > <?xml version='1.0' encoding='UTF-8'?>
> > > <atom:entry xmlns:atom="http://www.w3.org/2005/Atom";>
> > >   <atom:category scheme="http://schemas.google.com/g/2005#kind";
> > >       term="http://schemas.google.com/docs/2007#spreadsheet"; />
> > >   <atom:title>example spreadsheet</atom:title>
> > > </atom:entry>
>
> > > anyway both of them doesn't work for me, can any body give me an
> > > working example?
>
> > > And I paste my code if it helps
> > > ==============================================================
> > >                 StreamReader sr1 = new StreamReader("test.xls");
> > >                 String xlsStrData = sr1.ReadToEnd();
> > >                 ASCIIEncoding encoding = new ASCIIEncoding();
>
> > >                 String postBodyStr =
> > >                     "--END_OF_PART\r\n" +
> > >                     "Content-Type: application/atom+xml\r\n" +
> > >                     "\r\n" +
>
> > >                     "<entry xmlns='http://www.w3.org/2005/
> > > Atom'><category scheme='http://schemas.google.com/g/2005#kind'
> > > term='http://schemas.google.com/docs/2007#spreadsheet'
> > > label='spreadsheet'></category><title type='text'>test.xls</
> > > title><content type='application/vnd.ms-excel'></content></entry>\r\n"
> > > +
> > >                     //"<?xml version='1.0' encoding='UTF-8'?>\r\n" +
> > >                     //"<atom:entry xmlns:atom='http://www.w3.org/2005/
> > > Atom'>\r\n" +
> > >                     //"<atom:category scheme='http://
> > > schemas.google.com/g/2005#kind' term='http://schemas.google.com/docs/
> > > 2007#spreadsheet' />\r\n" +
> > >                     //"<atom:title>example spreadsheet</atom:title>\r
> > > \n" +
> > >                     //"</atom:entry>\r\n"+
> > >                     "--END_OF_PART\r\n" +
> > >                     "Content-Type: application/vnd.ms-excel\r\n" +
> > >                     "\r\n\r\n\r\n" + xlsStrData + "\r\n" +
> > >                     "--END_OF_PART--\r\n";
>
> > >                 byte[] postBodyData =
> > > encoding.GetBytes(postBodyStr);
>
> > >                 HttpWebRequest req =
> > > (HttpWebRequest)WebRequest.Create(url);
> > >                 req.Method = "POST";
> > >                 req.ContentLength = postBodyData.Length;
> > >                 req.ContentType = "multipart/related;boundary=
> > > \"END_OF_PART\"";
> > >                 //req.AllowAutoRedirect = true;
> > >                 //req.AllowWriteStreamBuffering = true;
>
> > >                 String op = "Authorization: GoogleLogin ";
> > >                 op += token;
> > >                 req.Headers.Add(op);
> > >                 req.Headers.Add("Slug: test.xls");
>
> > >                 //req.Headers.Add("Accept-Encoding: gzip");
> > >                 //req.Headers.Add("Cache-Control: no-cache");
> > >                 //req.Headers.Add("Pragma: no-cache");
> > >                 //req.Accept = "Accept: text/html, image/gif, image/
> > > jpeg, *; q=.2, */*; q=.2";
> > >                 //req.Headers.Add("MIME-version: 1.0");
>
> > >                 Stream postbody = req.GetRequestStream();
> > >                 postbody.Write(postBodyData, 0, postBodyData.Length);
> > >                 postbody.Close();
>
> > >                 WebResponse result = req.GetResponse();
> > > =======================================================================
> > > thanks ahead- Hide quoted text -
>
> > - Show quoted text -


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Data API" 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-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to