• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Google Docs Upload

Guest
Jun 02, 2011 Jun 02, 2011

Copy link to clipboard

Copied

Hey all,

I am working off the google API put together by Ray Camden to allow interactions with google docs. I am attempting to build a function to upload documents, but I am not quite sure how to put together the HTTP request. I just keep getting rejected no matter what I do. I've tried having the file content as a form field param and in the body of the request, both get rejected.

The docs for uploading are here
http://code.google.com/apis/documents/docs/2.0/developers_guide_protocol.html#UploadingDocs

This is my function as it stands. I keep getting bad request errors (error 400)

<cffunction name="upload" access="public" returnType="any" hint="I upload the document." output="false">     <cfargument name="myFile" type="string" required="false" hint="file to upload.">         <cfset var result = "">            <cfset theUrl = "https://docs.google.com/feeds/documents/private/full HTTP/1.1">     <cffile action="read" file="C:\website\xerointeractive\testing\test.txt" variable="theFile">     <cfset fileSize = createObject("java","java.io.File").init("C:\website\xerointeractive\testing\test.txt").length()>         <cfhttp url="#theURL#" method="post" result="result" charset="utf-8" >         <cfhttpparam type="header" name="Authorization" value="GoogleLogin auth=#getAuth()#">         <cfhttpparam type="header" name="Content-Type" value="text/plain">         <cfhttpparam type="header" name="Slug" value="test file">         <cfhttpparam type="header" name="Content-Length" value="#fileSize#">         <cfhttpparam type="body" name="file" value="#theFile#">     </cfhttp>         <cfreturn result> </cffunction>

You can see a what it is doing here

http://xerointeractive.com/testing/docstest.cfm

(may change as I am working on it)

I also built a page to print out the headers and data sent to it on request, and pointed my uploader to it. These are the results I got.

http://i.imgur.com/ykk7H.png

All in all the request looks good to me. I'm not real sure what I'm doing wrong. Any insight would be useful. Thanks!

TOPICS
Advanced techniques

Views

692

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 02, 2011 Jun 02, 2011

Copy link to clipboard

Copied

LATEST

Woot, I got it. I had to send the gData version number, and change the URL.

Here is the working function.

<cffunction name="upload" access="public" returnType="any" hint="I upload the document." output="false">     <cfargument name="myFile" type="string" required="false" hint="file to upload.">         <cfset var result = "">            <cfset theUrl = "https://docs.google.com/feeds/default/private/full">         <cffile action="read" file="C:\website\xerointeractive\testing\test.txt" variable="theFile">     <cfset fileSize = createObject("java","java.io.File").init("C:\website\xerointeractive\testing\test.txt").length()>         <cfhttp url="#theURL#" method="post" result="result" charset="utf-8" >         <cfhttpparam type="header" name="Authorization" value="GoogleLogin auth=#getAuth()#">         <cfhttpparam type="header" name="Content-Type" value="text/plain">         <cfhttpparam type="header" name="Slug" value="test file">         <cfhttpparam type="header" name="GData-Version" value="3">         <cfhttpparam type="header" name="Content-Length" value="#fileSize#">         <cfhttpparam type="body" value="#theFile#">     </cfhttp>         <cfreturn result> </cffunction>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation