Can't upload to google docs from php 400 error!
Hi guys I'm trying to upload to google docs on a google apps account using the following code - I'm using zend framework:
function getGoogleClient($s = '')
{
$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
$user = 'aaaaa';
$pass = 'aaaaa';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
return $httpClient;
}
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);
}
$client = getGoogleClient();
$docs = new Zend_Gdata_Docs($client);
$ls = uploadDocument($docs, true, $file->filename, $file->tmp_name);
BUt I keep getting this error - whats wrong here :(
Expected response code 200, got 400 Inconsistent repeating query parameter
There is a "bug" in Zend_Gdata_Docs with the mimetype. If you are using a temporary file and the filename as the title it will not auto-magically pull the mimetype for you. It tries to pull the mimetype based on the fileLocation extension which does not exist on a temporary file.
I made a class that works for me, rather than updating the Zend class. It is called ConvertDoc because I wanted to be able to upload a spreadsheet and download as csv.
What you really need is this...
// get mimetype from original file name
$filenameParts = explode('.', $originalFileName);
$fileExtension = end($filenameParts);
$mimeType = Zend_Gdata_Docs::lookupMimeType($fileExtension);
And pass the $mimetype instead of null.
精彩评论