cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We want to hear from you. What do you use Dropbox for?
Close

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: 
Highlighted

Unknown error on upload

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
Highlighted

Re: Unknown error on upload

Dropboxer
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.

Highlighted

Re: Unknown error on upload

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!).

 

Polls
Do you know how to organize your files and folders?
<b>We have created a guide on folder best practice, so you can get organized now <a href="https://www.dropboxforum.com/t5/Business-Tips-tricks/Folder-structure-best-practice/m-p/428456#M39"><u>check it out here</u></a>.</b>

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?