无法通过REST API将多个文件上传到Google云端硬盘

时间:2019-01-07 05:05:15

标签: c++ qt google-api google-drive-api

我的程序监视指定目录的更改,并将每个新检测到的文件的绝对路径发送到队列。当我的Google云端硬盘界面准备好下一个文件时,它会向队列发送信号,然后该队列返回要上传到该界面的文件路径。我的问题是,如果在第一个文件完成上传之前检测到多个文件,我的程序将尝试上传队列中的下一个文件,但QNetWorkReply将永远不会发出finish()。如果我等到第一个文件上传完毕,然后再移动文件以便检测到,则第二个文件将正确上传。

我认为这与更改googleDriveInterface :: uploadFile中的作用域有关,它可以完成上传,但我不确定如何解决此问题。

//connections made in main.cpp

//GOOGLE DRIVE INTERFACE MEMBER FUNCTIONS    

void 
googleDriveInterface::slotUploadFileToDrive(const QString &filePath){
QFileInfo file(filePath);
if (file.isDir() || file.size() > 52428800) {
    qDebug() << "unable to upload: " << filePath << "either >50mb or a directory";
    emit readyForNextUpload(); //get next file to upload
}
else {
    uploadFile(filePath);
}
}

void
googleDriveInterface::uploadFile(const QString &filePath){
    //code to initialize request
    networkReply = networkManager->post(request, multiPart);
    QObject::connect(networkReply, SIGNAL(finished()), this, SLOT(slotUploadResult()), Qt::DirectConnection);
}

void 
googleDriveInterface::slotUploadResult() {
    int statusCode = networkReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); //we need to convert to int so we can use it with switch/case

    switch (statusCode) {
    case 200: //nothing to do, file succesfully uploaded
        qDebug() << "file succuessfully uploaded to Google Drive";
        emit readyForNextUpload(); //let program now we are ready for next file 
        break;  
//rest of error handling
}


//QUEUE MEMBER FUNCTIONS
void
googleFileUploadQueue::slotShouldSendNextFile() {

    fileQueue.dequeue(); //file at front of queue has been taken care of
    if (!fileQueue.isEmpty()) {
        emit nextFileToUpload(fileQueue.head());
    }
}

void
googleFileUploadQueue::slotAddFileToQueue(const QString &filePath) {
    fileQueue.enqueue(filePath);
    if (fileQueue.size() == 1) { //queue was previously empty and we can send file for upload right away
        emit nextFileToUpload(filePath);
    }
}

0 个答案:

没有答案