Expand "addFileFromUrl" in GraphQL mutation

Hi,

To upload a file in script the following is required using fibery.addFileFromUrl(…) passing 5 arguments:

  1. HTTP(s) url
  2. File name
  3. Entity type
  4. Entity id
  5. Authentication headers which should be provided if url is not public and secured. Provide null or {} if auth is not needed
const fibery = context.getService('fibery');

for (const entity of args.currentEntities) {
    await fibery.addFileFromUrl(`https://fibery-public-assets.s3.amazonaws.com/apps/integrations/gitlab.png`, `gitlab.png`, entity.type, entity.id, null);
}

In GraphQl only two parameters is exposed:

snap814

Please expand to enable the passing of the authentication to the url using a GraphQl mutation. Passing the authentication token as part of the url sting does not seem to work.

Did you try accessing the graphQL API from curl, where you can add the Auth header explicitly?

escape() { perl -e '$_=do{local $/; <STDIN>}; s/\t/\\t/g; s/"/\\"/g; s/\n/\\n/g; print'; }
data="{\"query\": \"$(escape "$query")\"}"
curl --silent -X POST "$fiberyUrl" \
 -H "Authorization: Token $FiberyAPIkey" \
 -H 'Content-Type: application/json' \
 -d "$data" 
1 Like

Hi Matt,
Yes, I have used curl. The problem is not with the authorization to GraphQL but in the GraphQL mutation:

mutation {
  messages(id: { is: "xxxxxxxxxxxx" }) {
    addFileFromUrl(
      name: "test.jpeg"
      url: "https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=xxxxxxxx?access_token=xxxxxxxxx")
        {
      message
    }
  }
}

The fibery API and GraphQL api operation “addFileFromUrl” allows the URL to be passed from where the file data needs to be fetched.

If the file url requires authentication, the only way to pass it is using using inline authentication in the url string, in the following format : “https://looka…?mid=xxxxxxxx?access_token=xxxxxxxxx”

This should work but does not.

When I run the mutation in the Fibery browser GraphiQL I get the following error:

{
  "errors": [
    {
      "message": "We have troubles with accessing URL or uploading file: upload from url failed",
      "locations": [
        {
          "line": 33,
          "column": 3
        }
      ],
      "path": [
        "messages"
      ]
    }
  ],
  "data": {
    "messages": null
  }
}

This appears to confirm the suspected problem related to how the authentication is passed in the mutation url string.

Using the mutation to upload a file from an URL without authentication works perfect.

1 Like

Elaborate but functional api based workarounds due to the “addFileFromUrl” limitation:

  1. Retrieve file data from authenticated server.
  2. Use the file data and save it as a file in Dropbox.
  3. Use the Dropbox api to create a shared url link to the saved file.
  4. Use the Dropbox url to the file in the in the GraphQL mutation to upload the file to the Fibery entity.
1 Like