Fix "Bad request" issue when creating files
Open, HighPublic

Description

Currently it's not possible to create new files (new folders work, though).
The new file gets uploaded, but at the end of the process (which may take a while if the file is big), a "Bad request" popup is displayed and the upload job is aborted.

Screenshot of the error message:

The problem is that FileCreateJob exits with error 400 (which means invalid/malformed request).

ago 09 12:35:24 arch-x220 kdeinit5[10267]: kf5.kio.gdrive: Running job KGAPI2::Drive::FileCreateJob(0x7ffc77b96870) with accessToken "ya29.CjE6A36VN3HBp-23Dx2z39PzH7wCFeFPuqZbNdX1f9QT1dHZmR08Dw4PH2FB0wNNkEPU"
ago 09 12:35:27 arch-x220 kdeinit5[10267]: kf5.kio.gdrive: 400 "Bad request."

So it seems that this issue might come from libkgapi...

Relevant debug output from libkgapi:

ago 09 15:32:14 arch-x220 kdeinit5[20564]: org.kde.kgapi: KGAPI2::Drive::FileCreateJob(0x7ffc77b96940) Dispatching request to QUrl("https://www.googleapis.com/drive/v2/files?convert=false&ocr=false&pinned=false&useContentAsIndexableText=false&uploadType=multipart")
...
ago 09 15:32:16 arch-x220 kdeinit5[20564]: org.kde.kgapi: Received reply from QUrl("https://www.googleapis.com/drive/v2/files?convert=false&ocr=false&pinned=false&useContentAsIndexableText=false&uploadType=multipart")
ago 09 15:32:16 arch-x220 kdeinit5[20564]: org.kde.kgapi: Status code:  400
ago 09 15:32:16 arch-x220 kdeinit5[20564]: org.kde.kgapi.raw: "{\n \"error\": {\n  \"errors\": [\n   {\n    \"domain\": \"global\",\n    \"reason\": \"wrongUrlForUpload\",\n    \"message\": \"Uploads must be sent to the upload URL. Re-send this request to https://www.googleapis.com/upload/drive/v2/files?convert=false&ocr=false&pinned=false&useContentAsIndexableText=false&uploadType=multipart\"\n   }\n  ],\n  \"code\": 400,\n  \"message\": \"Uploads must be sent to the upload URL. Re-send this request to https://www.googleapis.com/upload/drive/v2/files?convert=false&ocr=false&pinned=false&useContentAsIndexableText=false&uploadType=multipart\"\n }\n}\n"
ago 09 15:32:16 arch-x220 kdeinit5[20564]: org.kde.kgapi: Bad request, Google replied ' "{\n \"error\": {\n  \"errors\": [\n   {\n    \"domain\": \"global\",\n    \"reason\": \"wrongUrlForUpload\",\n    \"message\": \"Uploads must be sent to the upload URL. Re-send this request to https://www.googleapis.com/upload/drive/v2/files?convert=false&ocr=false&pinned=false&useContentAsIndexableText=false&uploadType=multipart\"\n   }\n  ],\n  \"code\": 400,\n  \"message\": \"Uploads must be sent to the upload URL. Re-send this request to https://www.googleapis.com/upload/drive/v2/files?convert=false&ocr=false&pinned=false&useContentAsIndexableText=false&uploadType=multipart\"\n }\n}\n" '

So it looks like FileCreateJob is sending requests to this URL:

https://www.googleapis.com/drive/v2/files?convert=false&ocr=false&pinned=false&useContentAsIndexableText=false&uploadType=multipart

while google is expecting them to this other URL:

https://www.googleapis.com/upload/drive/v2/files?convert=false&ocr=false&pinned=false&useContentAsIndexableText=false&uploadType=multipart\

In practice there is just a missing /upload/ immediately after the domain name.

elvisangelaccio moved this task from Backlog to Done on the KIO GDrive board.Aug 9 2016, 3:22 PM