2

Googleドライブに任意のファイルタイプをアップロードするためのフォームとGoogleAppEngineを使用したシンプルなサーバーを作成しました。フォームは特定のファイルタイプでは機能せず、代わりに次のエラーが発生します。

HttpError: <HttpError 400 when requesting https://www.googleapis.com/upload/drive/v1/files?alt=json returned "Unsupported content with type: application/pdf">

PDFファイルはサポートされていませんか?

アップロードを行うappengineコードは、次のようになります。

def upload_to_drive(self, filestruct):
    resource = {
        'title': filestruct.filename,
        'mimeType': filestruct.type,
    }
    resource = self.service.files().insert(
    body=resource,
    media_body=MediaInMemoryUpload(filestruct.value,
                                     filestruct.type),
    ).execute()


def post(self):
      creds = StorageByKeyName(Credentials, my_user_id, 'credentials').get()
      self.service = CreateService('drive', 'v1', creds)
      post_dict = self.request.POST
      for key in post_dict.keys():
          if isinstance(post_dict[key], FieldStorage):#might need to import from cgi
             #upload to drive and return link
             self.upload_to_drive(post_dict[key]) #TODO: there should be error handling here

MSOfficeのドキュメントや画像に使用できました。テキストファイルでも機能せず、次のエラーが発生します。

HttpError: <HttpError 400 when requesting https://www.googleapis.com/upload/drive/v1/files?alt=json returned "Multipart content has too many non-media parts">

リソース辞書の「mimeType」値の設定を解除して、Googleドライブに自動的に設定させてみました。また、MediaInMemoryUploadコンストラクターでmimeタイプの値の設定を解除してみました。悲しいことに、両方とも機能しませんでした。

4

1 に答える 1

5

古いバージョンのPythonクライアントライブラリを使用していて、Drive API v1を参照しているようですが、DriveAPIv2は6月末から利用可能になっています。

ライブラリを更新して、 https://developers.google.com/drive/examples/pythonで完全なPythonサンプルを確認してください。

于 2012-08-10T16:38:34.883 に答える