Подтвердить что ты не робот

Загрузка файлов на Google Диск с использованием ColdFusion

* НОВОЕ ОБНОВЛЕНО ДЛЯ ЛУЧШЕЙ ВТОРОЙ ЧАСТИ - ТЕПЕРЬ ПОЛУЧАЕТСЯ "308 Возобновить незавершенное", хотя файл должен быть только одной загрузкой!

Я использую основу cfgoogle от Ray Camden. Но Google устарел на код для загрузки документов. Новый стандарт Возобновляемые загрузки мультимедиа.

У меня есть эта часть, работающая (вплоть до "Инициирование возобновляемого запроса на загрузку" ) в вышеупомянутом документе Google.

Страница вызова:

<cfset application.cfc.Google                   = createObject('component','#path_cf_cfc#Google') />
<cfset application.cfc.GoogleDocs               = createObject('component','#path_cf_cfc#GoogleDocs') />

<cfset gtoken = application.cfc.GoogleDocs.authenticate(emailaddress,password)>

<CFSET testdoc = "a\filepath\documentname.doc">
<CFSET FileType = "application/msword">
<CFSET FileTitle = "test_001">

<cfset temp = application.cfc.GoogleDocs.upload_auth("#Application.Map.DocStorage##tv.testdoc#",FileType,FileTitle)>  

<CFSET uploadpath = Listgetat(Listgetat(temp.header,ListContains(temp.header,"https://docs.google.com","#chr(10)#"),"#chr(10)#"),2," ") >  

<cfset temp2 = application.cfc.GoogleDocs.upload_file("#Application.Map.DocStorage##tv.testdoc#",FileType,FileTitle,uploadpath)>

Код работает вплоть до строки cfset temp (получение уникального URI загрузки)

Вот код для upload_auth:

<cffunction name="upload_auth" access="public" returnType="any" hint="I get a uniqu URI from Google API." output="false">
<cfargument name="myFile" type="string" required="true" hint="filepath to upload.">
<cfargument name="myType" type="string" required="true" hint="application/msword"> 
<cfargument name="myTitle" type="string" required="true" hint="name of doc"> 

<cfset GoogleUrl = "https://docs.google.com/feeds/upload/create-session/default/private/full">
<cfset GoogleVersion = 3> 
<cfset FileSize = createObject("java","java.io.File").init(myFile).length()>

<cfhttp url="#GoogleUrl#" method="post" result="diditwork" resolveurl="no">
<cfhttpparam type="header" name="Authorization" value="GoogleLogin auth=#getAuth(variables.docservice)#">
<cfhttpparam type="header" name="GData-Version" value="#GoogleVersion#">
<cfhttpparam type="header" name="Content-Length" value="0">
<cfhttpparam type="header" name="X-Upload-Content-Type" value="#myType#">
<cfhttpparam type="header" name="X-Upload-Content-Length" value="#FileSize#">
<cfhttpparam type="header" name="Slug" value="#myTitle#">

</cfhttp>

<cfreturn diditwork>
</cffunction>

ОК - так хорошо. Но вот где он ломается:

Запуск upload_file возвращает "308 Resume Uncomplete" (а не 400!) из Google. Arrgh!!

Вот файл upload_file -

<cffunction name="upload_file" access="public" returnType="any" hint="I upload the document." output="false">
<cfargument name="myFile" type="string" required="true" hint="filepath to upload.">
<cfargument name="myType" type="string" required="true" hint="like application/msword"> 
<cfargument name="myTitle" type="string" required="true" hint="name of doc"> 
<cfargument name="myAuthPath" type="string" required="true" hint="call auth"> 

<cfset FileSize = GetFileInfo(myFile).size >
<CFSET tv.tostartwithzero = FileSize - 1>

<CFFILE action="read" file="#myfile#" variable="FileText">

<cfhttp url="#myAuthPath#" method="put" result="diditwork" resolveurl="no" multipart="yes" charset="utf-8" >
<cfhttpparam type="header" name="Authorization" value="GoogleLogin auth=#getAuth(variables.docservice)#">
<cfhttpparam type="header" name="GData-Version" value="#variables.GoogleVersion#">
<cfhttpparam type="header" name="Content-Length" value="#FileSize#">
<cfhttpparam type="header" name="Content-Range" value="bytes 0-#tv.tostartwithzero#/#FileSize#">
<cfhttpparam type="header" name="Content-Type" value="#myType#">

<cfhttpparam type="body" value="#trim(FileText)#">

</cfhttp>

<cfreturn diditwork>
</cffunction>

Итак, там у нас есть - где я застрял. Я могу получить уникальный URI, но (возможно, потому, что это поздно ночью). Я мертв мозгом в отношении того, что я делаю неправильно, иначе для завершения загрузки файла.

Вся помощь приветствуется.

4b9b3361

Ответ 1

Я настоятельно рекомендую использовать здесь другой подход. Есть два больших вопроса, которые вы делаете:

  • Похоже, что код использует устаревший механизм авторизации входа в систему и использует имя пользователя/пароль вместо OAuth.
  • Использование API списков устаревших документов вместо нового API дисков.

Поскольку вы можете вызвать java, я бы предложил написать код загрузки в простой Java, а затем вызвать его с ваших CF-страниц по мере необходимости.