diff --git a/src/uas/QGCUASFileManager.cc b/src/uas/QGCUASFileManager.cc index edcb720d272982f3084604c8721501f0cd023c12..fe4e5a103b5ae6641a6db68516f59a699fd0d851 100644 --- a/src/uas/QGCUASFileManager.cc +++ b/src/uas/QGCUASFileManager.cc @@ -475,16 +475,16 @@ void QGCUASFileManager::uploadPath(const QString& toPath, const QFileInfo& uploa } QFile file(uploadFile.absoluteFilePath()); - if (!file.open(QIODevice::ReadOnly | QIODevice::Truncate)) { + if (!file.open(QIODevice::ReadOnly)) { _emitErrorMessage(tr("Unable to open local file for upload (%1)").arg(uploadFile.absoluteFilePath())); return; } _writeFileAccumulator = file.readAll(); - qint64 bytesRead = file.write((const char *)_readFileAccumulator, _readFileAccumulator.length()); - if (bytesRead <= 0) { - file.close(); + file.close(); + + if (_writeFileAccumulator.size() == 0) { _emitErrorMessage(tr("Unable to read data from local file (%1)").arg(uploadFile.absoluteFilePath())); return; } @@ -495,7 +495,7 @@ void QGCUASFileManager::uploadPath(const QString& toPath, const QFileInfo& uploa request.hdr.session = 0; request.hdr.opcode = kCmdCreateFile; request.hdr.offset = 0; - request.hdr.size = bytesRead; + request.hdr.size = 0; _fillRequestWithString(&request, toPath); _sendRequest(&request); } diff --git a/src/ui/QGCUASFileView.cc b/src/ui/QGCUASFileView.cc index 9ef758bcfeab6d4e9dea13b29241f92220e3d09d..94ce2e5402013d8d1eca1bb45afeb18a1ef7456e 100644 --- a/src/ui/QGCUASFileView.cc +++ b/src/ui/QGCUASFileView.cc @@ -100,19 +100,25 @@ void QGCUASFileView::_uploadFile(void) _ui.statusText->clear(); - // And now download to this location - QString path; + // get and check directory from list view QTreeWidgetItem* item = _ui.treeWidget->currentItem(); if (item && item->type() != _typeDir) { return; } - QString targetDir = item->text(0); + // Find complete path for upload directory + QString path; + do { + QString name = item->text(0).split("\t")[0]; // Strip off file sizes + path.prepend("/" + name); + item = item->parent(); + } while (item); + qDebug() << "Upload: " << path; QString uploadFromHere = QGCFileDialog::getOpenFileName(this, tr("Upload File"), QDir::homePath()); - _manager->uploadPath(targetDir, uploadFromHere); + _manager->uploadPath(path, uploadFromHere); }