How is your experience with the OutSystems Community?
7
Views
2
Comments
[Google Drive Integration] How to correctly upload a .docx file to a specific Google Drive folder via Direct RES
Google Drive Integration
Forge asset by valantic LCS
Application Type
Reactive
Service Studio Version
11.55.73 (Build 64880)
Platform Version
11.41.2 (Build 47258)

Desperately need help: How to upload a .docx file to a specific Google Drive folder via REST API (Service Account OAuth2 JWT) in Reactive? Been stuck for 1 week.

Body:

Hi Community,

I am writing this out of sheer frustration as I have been stuck on this issue for an entire week now, trying every possible configuration, but I keep hitting a wall. I desperately need the expertise of anyone who has successfully implemented this.

I am working on a Google Drive integration in a Reactive Web Application using a Service Account (headless approach).

What is working perfectly: My token exchange is completely fine.

  1. I generate a JWT from a PEM string private key using the GenerateJwtFromPemString action from a Forge component.

  2. I pass the JWT assertion to the Google OAuth2 token endpoint (https://oauth2.googleapis.com/token) via a standard REST API method (Form URL Encoded, Send In Body) and get a valid access_token (Bearer).

Where I am failing miserably (The Issue): The problem occurs during the file upload phase when trying to upload a .docx (Microsoft Word) file.

  • Using Forge Components: Initially, using standard Forge components (GoogleDriveIntegration), I encountered continuous serialization or bad request errors (400 Bad Request or parsing issues like the infamous Infinity value parsing error).

  • Using Direct REST API (uploadType=media): To bypass the Forge component, I consumed Google Drive's API directly (https://www.googleapis.com/upload/drive/v3/files?uploadType=media). This returns a 403 Forbidden error. I found out it's because a pure binary media stream attempts to write to the Service Account's default Root ("My Drive"), which doesn't exist or is restricted. Also, Google doesn't allow passing the parents query parameter in a simple media upload type.

  • Using Direct REST API (uploadType=multipart): I tried shifting to a multipart request to pass the metadata and the file together. However, constructing a valid multipart raw request body with text boundaries (--boundary, JSON metadata for the parents folder array, and the base64 or binary content) inside OutSystems' REST body parameter is corrupting the .docx file structure or returning 400 Bad Request.

Goal: I just need to upload a .docx file from an Upload widget directly into a specific shared Google Drive folder ID (1e_K9qJNokCja1yQYoSPkKZDEGxVHmZxw) where my Service Account email already has "Editor" permissions.

Questions:

  1. Is there any way to use uploadType=media but force it into a specific folder (maybe via headers), or is multipart absolutely mandatory for this?

  2. If multipart is required, what is the exact, correct way to format the REST Body in OutSystems so it passes the JSON metadata and the binary file without breaking the document structure?

  3. Is there a lightweight Forge component or an Integration Studio extension you can recommend that successfully handles headless Service Account uploads for document files?

I’ve spent 7 days debugging this non-stop and I'm completely out of ideas. Any help, sample .oml files, or logic screenshots would literally save my life.

Thank you so much in advance!

googletestsss.oml
2023-08-28 07-00-10
Paulo Torres
Champion

Hello,

I think is a good idea if you open a post under the support of the component you are using.

UserImage.jpg
jesu verso

almost forgot it! thanks

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.