0

APIドキュメントから:

ファイルが手動でアップロードされた場合は元のファイル名、ファイルが API を介して挿入された場合は元のタイトル。タイトルの名前を変更しても、元のファイル名は変更されないことに注意してください。これは、ドライブにコンテンツが保存されているファイルにのみ入力されます。

タイトルと元のファイル名が異なるファイルを挿入したいと考えています。ドキュメントの (私の解釈) によると、これは 2 段階のアプローチになります。最初に元のファイル名になるタイトルのドキュメントを挿入し、次にパッチを実行してタイトルを変更します。タイトルと元のファイル名を区別するには、2 つの手順が必要です。また、API を使用して元のファイル名を変更することはできません。

元のファイル名を設定するより良い方法はありますか?

4

2 に答える 2

1

We were looking to keep the original file-name of the revision file being uploaded in the history list when the actual file in Google drive had a different name.

We wanted the Google drive file to be named with a static name and all the revisions in the history list to contain the date in their file-names.

There is not direct functionality available to do that through the Google Drive API.

The natural thing springing into mind was to update the revision's originalFilename field through the API (we are using NodeJS with module "googleapis" v3)

service.revisions.update(
    {
             fileId: <fileId>,
             revisionId: <revisionId>,
             resource: {
                  originalFilename : <revision file name>
             }
    }
)

But the response was :

{
      Error: The resource body includes fields which are not directly writable.
      code: 403,  
      errors:
      { 
           domain: 'global',
           reason: 'fieldNotWritable',
           message: 'The resource body includes fields which are not directly writable.'
      } 
}

So it turned out the originalFilename field was recognizable on revisions.update but somehow not updatable - may be done like that on purpose for some reason.

The workaround that we used which actually managed to achieve our initial goal was to programmatically :

  1. Rename the google drive file, before uploading the revision, to the revision's file name
  2. Upload the revision to the google drive ( now the originalFilename of the revision is being automatically set to the actual file name which we conveniently renamed on the previous step to be the revisions file name )
  3. Rename the google drive file to its original file name

So if we have google drive file named "GooleDriveFile.dat" and we want to upload revision named GooleDriveFile_01012016.dat and to keep the original revision name in the history list we can programmatically :

1-> rename the google drive file from GooleDriveFile.dat to GooleDriveFile_01012016.dat

service.files.update(
      {
          fileId : <fileId>,
          resource: {
               name: "GooleDriveFile_01012016.dat",
          },
          fields :  "id,headRevisionId"
      } 
) 

2-> Upload the revision to the google drive

service.files.update(
   {
        fileId : <fileid>,
        newRevision : true,
        keepRevisionForever : true,
        media: {
            body: fs.createReadStream(<local path to the revision file>)  
        },
        fields : "id,headRevisionId"
    }
)

3-> Rename the google drive file back to "GooleDriveFile.dat"

service.files.update(
      {
          fileId : <fileId>,
          resource: {
               name: "GooleDriveFile.dat",
          },
          fields :  "id,headRevisionId"
      } 
) 
于 2016-01-29T12:34:40.027 に答える
0

実際、insert()を実行してからpatch()を実行しても、originalFilenameを返すことができませんでした。ドキュメントに「ファイルが手動でアップロードされた場合」と記載されている場合、それはユーザーがドライブWebUIを介してファイルをアップロードしていることを示していると思います。

indexableTextやdescriptionなどの他の属性に元のファイル名を記録する方がよい場合があります。

于 2012-12-05T13:50:40.307 に答える