cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Back again with another edition of 'How we use Dropbox', so find out how Ross uses Dropbox to answer some new house questions here!

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unknown error on upload

Unknown error on upload

philman
Explorer | Level 4

Dear support,

 

I would like to upload files to my Dropbox Application via Qt in c++ but it returns "unknown error" despite the "curl -X POST" equivalent is working like a charm in CLI mode.

Do you what is wrong?

 

Here the code in QT Creator I wrote:

dropbox.h

#ifndef DROPBOX_H
#define DROPBOX_H

#include <QObject>
#include <QtNetwork/QNetworkAccessManager>

class DropBox : public QNetworkAccessManager
{
    Q_OBJECT

public:
    explicit DropBox(QObject *parent = nullptr) : QNetworkAccessManager(parent) {}
    void upload(const QString filename);

signals:

public slots:

private:
    
};

#endif // DROPBOX_H

dropbox.cpp

#include "dropbox.h"

#include <QFile>
#include <QNetworkReply>

void DropBox::upload(const QString filename)
{
    QNetworkRequest request(QUrl("https://content.dropboxapi.com/2/files/upload"));

    request.setRawHeader(QByteArray("Authorization"), QByteArray("Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
    QString dropboxArg = QString("{\"path\": \"/mouvdetect/QtHumanDetector/%1\",\"mode\": \"add\",\"autorename\": true,\"mute\": false,\"strict_conflict\": false}").arg(filename);
    request.setRawHeader(QByteArray("Dropbox-API-Arg"), dropboxArg.toUtf8());
    request.setRawHeader(QByteArray("Content-Type"), QByteArray("application/octet-stream"));

    QFile *file = new QFile(filename);
    file->open(QIODevice::ReadOnly);
    QByteArray content = file->readAll();
    request.setRawHeader(QByteArray("Content-Length"), QByteArray::number(content.size()));

    QNetworkReply *reply = this->post(request, content);

    QObject::connect(reply,
                     &QNetworkReply::finished,
                     [=](){
                        QString err = reply->errorString();
                        QString contents = QString::fromUtf8(reply->readAll());
                        qInfo() << "Error:" << err;});
}

In the above code, please replace the automatic emoji with "opening bracket equal sign closing bracket"

 

Please tell me if you need more information on how to compile and run this code with Qt Creator.

 

Best regards,

Philman

2 Replies 2

Re: Unknown error on upload

Greg-DB
Dropboxer

I don't believe the "unknown error" message is coming from Dropbox itself, so it's likely coming from the client you're using. We can't provide support for the client itself though, as it's not made by Dropbox.

 

Can you enable any extra logging or verbose mode though? If the Dropbox API request itself is failing, the Dropbox API HTTPS response would contain a more helpful error message.

Re: Unknown error on upload

philman
Explorer | Level 4

Thank you Greg, for your prompt answer.

In fact, the message "unknown error" was thrown even if the file was well uploaded (so I was confused and I didn't check before if the file was effectively uploaded or not... oh my!).

 

Who's talking

Top contributors to this post

  • User avatar
    philman Explorer | Level 4
  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?