Uploading documents with zend - need help

193 views
Skip to first unread message

tm

unread,
Oct 24, 2009, 4:47:30 PM10/24/09
to Google Documents List API
Hello,

im trying do uploading a document to specific folder using php with
zend:

Im using this code:

function uploadDocument($docs, $html, $originalFileName,
$temporaryFileLocation) {
$fileToUpload = $originalFileName;
if ($temporaryFileLocation) {
$fileToUpload = $temporaryFileLocation;
}

$newDocumentEntry = $docs->uploadFile($fileToUpload,
$originalFileName,
null, Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI);

echo "New Document Title: ";

if ($html) {
$alternateLink = '';
foreach ($newDocumentEntry->link as $link) {
if ($link->getRel() === 'alternate') {
$alternateLink = $link->getHref();
}
}

echo "<a href=\"$alternateLink\">\n";
}
echo $newDocumentEntry->title."\n";
if ($html) {echo "</a>\n";}
}


and i use it like this : uploadDocument($docs, true, "/home/user/
TEST.pdf", "");



it doesnt send and retrieves the error:

Notice: Undefined index: PDF in /ZendGdata/library/Zend/Gdata/Docs.php
on line 92

Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with
message 'Expected response code 200, got 400 Invalid repeating query
parameter ' in /ZendGdata/library/Zend/Gdata/App.php:700 Stack trace:
#0 /ZendGdata/library/Zend/Gdata.php(219): Zend_Gdata_App-
>performHttpRequest('POST', 'http://docs.goo...', Array, '%PDF-1.4?
%?????...', NULL, NULL) #1 /ZendGdata/library/Zend/Gdata/App.php(886):
Zend_Gdata->performHttpRequest('POST', 'http://docs.goo...', Array,
'%PDF-1.4?%?????...', NULL) #2 /ZendGdata/library/Zend/Gdata/App.php
(956): Zend_Gdata_App->post(Object(Zend_Gdata_App_MediaFileSource),
'http://docs.goo...', NULL, NULL, Array) #3 /ZendGdata/library/Zend/
Gdata/Docs.php(253): Zend_Gdata_App->insertEntry(Object
(Zend_Gdata_App_MediaFileSource), 'http://docs.goo...',
'Zend_Gdata_Docs...') #4 /ZendGdata/library/Zend/Gdata/Docs.php(234):
Zend_Gdata_Docs->insertDocument(Object
(Zend_Gdata_App_MediaFileSource), 'http://docs.goo...') #5 /opt/lampp/
htdocs/IRRISTRAT/CD_API/funcionais/DocsInsert.php(47): Zend_Gdata_Docs-
>u in /ZendGdata/library/Zend/Gdata/App.php on line 700.

Any help would be appreciated.
Thanks

Eric Bidelman

unread,
Oct 24, 2009, 7:11:32 PM10/24/09
to google-docum...@googlegroups.com
Add 'PDF' => 'application/pdf' to the SUPPORTED_FILETYPES 
Array in /ZendGdata/Docs.php.

Also, you may want to use this method from Docs.php
(or your own variant of it):
uploadFile($fileLocation, $title=null, $mimeType=null, $uri=null)

At passes in an URI, which is where you can specify which
folder to upload the doc to.

Eric

tm

unread,
Oct 25, 2009, 11:46:34 AM10/25/09
to Google Documents List API
Hi Eric,
first of all , thank you for answering,

I've added the variant to the Docs.php in the zend library, but im
still receiving the same error:

"...Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException'
with message 'Expected response code 200, got 415 Content-Type
application/pdf is not a valid input type.' in /ZendGdata/library/Zend/
Gdata/App.php (......)..."

I've tryied with a .txt and it work's but the pdf I cant undertstand
what going on.

any ideias?.
thanks

TM

tm

unread,
Oct 25, 2009, 5:25:10 PM10/25/09
to Google Documents List API
Hello again, I've been developing some other functions and I've got
some extra problems:


1) I cant download documents using this sample code:

function download($user,$pass, $url, $format=null) {
$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass,
$service);
$docs = new Zend_Gdata_Docs($client);
$sessionToken = $docs->getHttpClient()->getAuthSubToken(); //-
>getHttpClient()
$opts = array(
'http' => array(
'method' => 'GET',
'header' => "GData-Version: 3.0\r\n"."Authorization:
AuthSub token=\"$sessionToken\"\r\n"
)
);
if ($url != null) {
$url = $url . "&exportFormat=$format";
}
return file_get_contents($url, false, stream_context_create
($opts));
}

2) I cant upload documents to a specif folder but I can list them from
a specific folder.


function uploadDocument($user,$pass, $fileName,$fileLocation,
$folderName) {
$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass,
$service);
$docs = new Zend_Gdata_Docs($client);
$newDocumentEntry = $docs->uploadFile($fileLocation,
$fileName,null,$folderName);

echo "Documento enviado: ";
echo $newDocumentEntry->title."\n";
}


If anyone know how to do it please help.

Thanks

Eric Bidelman

unread,
Oct 28, 2009, 6:13:46 PM10/28/09
to google-docum...@googlegroups.com
If you're planning on using v3.0, see some of my changes to Docs.php here:
On Mon, Oct 26, 2009 at 8:25 AM, tm <tiagoh....@gmail.com> wrote:

Hello again, I've been developing some other functions and I've got
some extra problems:


1) I cant download documents using this sample code:

  function download($user,$pass, $url, $format=null) {
       $service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
       $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass,
$service);
       $docs = new Zend_Gdata_Docs($client);
       $sessionToken = $docs->getHttpClient()->getAuthSubToken();  //-
>getHttpClient()
       $opts = array(
          'http' => array(
            'method' => 'GET',
            'header' => "GData-Version: 3.0\r\n"."Authorization:
AuthSub token=\"$sessionToken\"\r\n"

You're mixing ClientLogin and AuthSub.  This sample method
used AuthSub to download a document.  If you're going to use
ClientLogin (username/password), you need to change
to the correct Authorization header:

However, if you're building a web app, you should really
be using AuthSub.
 
          )
       );
       if ($url != null) {
         $url =  $url . "&exportFormat=$format";
       }
       return file_get_contents($url, false, stream_context_create
($opts));
   }

2) I cant upload documents to a specif folder but I can list them from
a specific folder.

dan

unread,
Nov 24, 2009, 1:05:04 PM11/24/09
to Google Documents List API
hi tm - i'm getting the same error:

Error: 37 Content-Type application/pdf is not a valid input type.

did you ever find a solution?!

Thanks,

Dan

On Oct 28, 10:13 pm, Eric Bidelman <api.e...@google.com> wrote:
> If you're planning on using v3.0, see some of my changes to Docs.php here:http://code.google.com/p/gdata-samples/source/browse/trunk/doclist/OC...
> Seehttp://code.google.com/apis/documents/docs/2.0/developers_guide_proto...
Reply all
Reply to author
Forward
0 new messages