0

我希望用戶將文件上傳到Google雲端硬盤,但不是根文件。 Children資源只允許從根目錄列出文件夾(這很有意義),但不會將文件夾的名稱放在JSON響應中。將文件上傳到隨機文件夾中

我無法使用Parent資源,因爲fileID不存在,還因爲我需要用戶查看文件夾(在其各自的層次中)並選擇他們選擇的文件夾。這是我迄今試過的東西

void DriveClass::listFileFolderDrive(const QString& folderID){ 

QUrl url("https://www.googleapis.com/drive/v2/files/" + folderID + "/children"); 
//qDebug()<<" url for About Drive: "<< url; 
QNetworkRequest* request = new QNetworkRequest(url); 
request->setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); 
request->setRawHeader("Authorization", QString("Bearer %1").arg(this->_oAuth2->token()).toLatin1()); 
QNetworkReply* reply = m_networkManager->get(*request); 
bool result = connect(reply, SIGNAL(finished()), this, SLOT(onlistFileFolderDriveFinished())); 
Q_ASSERT(result); 
Q_UNUSED(result); 
} 

其中folderID是「root」。我得到的迴應是:

QVariant(QVariantMap, QMap(("etag", QVariant(QString, ""dyf6dc5nFpQUIZ2nJvOu2LyLJk8/bD3mjJonFeCjTc8Eu8VRx_DzPtg"")) ("items" , QVariant(QVariantList, (QVariant(QVariantMap, QMap(("childLink", QVariant(QString, "https://www.googleapis.com/drive/v2/files/0B_0rcYNi_Ycab1hhT3I0T3ptMDg")) ("id" , QVariant(QString, "0B_0rcYNi_Ycab1hhT3I0T3ptMDg")) ("kind" , QVariant(QString, "drive#childReference")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/0AP0rcYNi_YcaUk9PVA/children/0B_0rcYNi_Ycab1hhT3I0T3ptMDg"))) ) , QVariant(QVariantMap, QMap(("childLink", QVariant(QString, "https://www.googleapis.com/drive/v2/files/0B_0rcYNi_YcabXdJd21CeWRHUXM")) ("id" , QVariant(QString, "0B_0rcYNi_YcabXdJd21CeWRHUXM")) ("kind" , QVariant(QString, "drive#childReference")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/0AP0rcYNi_YcaUk9PVA/children/0B_0rcYNi_YcabXdJd21CeWRHUXM"))) ) , QVariant(QVariantMap, QMap(("childLink", QVariant(QString, "https://www.googleapis.com/drive/v2/files/0B_0rcYNi_YcaM1ZCOXBaZzJSNmc")) ("id" , QVariant(QString, "0B_0rcYNi_YcaM1ZCOXBaZzJSNmc")) ("kind" , QVariant(QString, "drive#childReference")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/0AP0rcYNi_YcaUk9PVA/children/0B_0rcYNi_YcaM1ZCOXBaZzJSNmc"))) ) , QVariant(QVariantMap, QMap(("childLink", QVariant(QString, "https://www.googleapis.com/drive/v2/files/0B_0rcYNi_YcaSmtNMmRlTld5QkU")) ("id" , QVariant(QString, "0B_0rcYNi_YcaSmtNMmRlTld5QkU")) ("kind" , QVariant(QString, "drive#childReference")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/0AP0rcYNi_YcaUk9PVA/children/0B_0rcYNi_YcaSmtNMmRlTld5QkU"))) ) , QVariant(QVariantMap, QMap(("childLink", QVariant(QString, "https://www.googleapis.com/drive/v2/files/0B_0rcYNi_YcaY0I0czA4djNLT1U")) ("id" , QVariant(QString, "0B_0rcYNi_YcaY0I0czA4djNLT1U")) ("kind" , QVariant(QString, "drive#childReference")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/0AP0rcYNi_YcaUk9PVA/children/0B_0rcYNi_YcaY0I0czA4djNLT1U"))) ) , QVariant(QVariantMap, QMap(("childLink", QVariant(QString, "https://www.googleapis.com/drive/v2/files/0B_0rcYNi_YcaTW8zZklsNnFNTDBmQ1dodi1yTFhqX2s4SzNr")) ("id" , QVariant(QString, "0B_0rcYNi_YcaTW8zZklsNnFNTDBmQ1dodi1yTFhqX2s4SzNr")) ("kind" , QVariant(QString, "drive#childReference")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/0AP0rcYNi_YcaUk9PVA/children/0B_0rcYNi_YcaTW8zZklsNnFNTDBmQ1dodi1yTFhqX2s4SzNr"))) ) , QVariant(QVariantMap, QMap(("childLink", QVariant(QString, "https://www.googleapis.com/drive/v2/files/1_eVyijBnZPvFfn4WewtScnlSXRFpXInmop-AUD6Jp5nSV4rnxL4-IpLZ6uoR")) ("id" , QVariant(QString, "1_eVyijBnZPvFfn4WewtScnlSXRFpXInmop-AUD6Jp5nSV4rnxL4-IpLZ6uoR")) ("kind" , QVariant(QString, "drive#childReference")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/0AP0rcYNi_YcaUk9PVA/children/1_eVyijBnZPvFfn4WewtScnlSXRFpXInmop-AUD6Jp5nSV4rnxL4-IpLZ6uoR"))) ) , QVariant(QVariantMap, QMap(("childLink", QVariant(QString, "https://www.googleapis.com/drive/v2/files/0B_0rcYNi_YcaYmNmZTEwMzYtNjgzZC00MjJkLWFmYWQtZmRlODc4OTEwZTVh")) ("id" , QVariant(QString, "0B_0rcYNi_YcaYmNmZTEwMzYtNjgzZC00MjJkLWFmYWQtZmRlODc4OTEwZTVh")) ("kind" , QVariant(QString, "drive#childReference")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/0AP0rcYNi_YcaUk9PVA/children/0B_0rcYNi_YcaYmNmZTEwMzYtNjgzZC00MjJkLWFmYWQtZmRlODc4OTEwZTVh"))) ) , QVariant(QVariantMap, QMap(("childLink", QVariant(QString, "https://www.googleapis.com/drive/v2/files/1CHu3CzJ23I6WS3J8rOIpT5szN8r8mTOxztiWixwXafQ")) ("id" , QVariant(QString, "1CHu3CzJ23I6WS3J8rOIpT5szN8r8mTOxztiWixwXafQ")) ("kind" , QVariant(QString, "drive#childReference")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/0AP0rcYNi_YcaUk9PVA/children/1CHu3CzJ23I6WS3J8rOIpT5szN8r8mTOxztiWixwXafQ"))) )) )) ("kind" , QVariant(QString, "drive#childList")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/root/children"))) ) 

我希望這已經夠清楚了。我在QVariant中解析它,以便在ListView中使用結果。從我學習谷歌驅動器文檔,需要一個文件有一個文件夾ID插入之前可以實現。而且我沒有要上傳的新文件的文件夾ID。

+0

我需要向我們展示您嘗試過的內容,並描述您在使用當前解決方案時遇到的任何問題。請閱讀http://stackoverflow.com/help/how-to-ask – DaImTo

+0

謝謝。我已經請求了根子文件夾的列表。這個問題已被重新編輯。 –

回答

0

是的,是相當錯誤的...直到現在。對於記錄,無論是文件還是文件夾,上傳到任何位置(無論是root還是任何RANDOM文件夾),都需要該特定文件夾的folder_id。使用「root」作爲根文件夾的ID。要上傳,您不需要selfLink或parentLink。只是

parents:[{ "id" : "id of the folder, use root for root folder" }] 

謝謝@pioyoyid。

0

一些指點...

  1. 您正在使用V2 API。如果這是一個新的應用程序,您應該切換到v3。
  2. 您的REST呼叫正在請求兒童資源列表。如果您查看https://developers.google.com/drive/v2/reference/children,您會看到兒童資源中沒有標題/名稱。
  3. 實現你要找的東西的更常見的方式是使用查詢參數folder_id in parents來執行files.list。
+0

這就是事情,但我沒有folder_id?如果要將一個新文件上傳到任何文件夾,是否意味着folder_id也將是「root」?,在父項中使用folder_id的查詢參數執行files.list。 –

+0

抱歉,我不瞭解您的評論。 – pinoyyid

+0

哦,我的意思是父母身份證,自然,你不需要folder_id上傳文件或文件。 –

相關問題