Getting image urls uploaded from @forestadmin/plugin-aws-s3

Feature(s) impacted

I have successfully setup uploading files to S3 from ForestAdmin, using :

Observed behavior

But when I list it in Forestadmin, I get this strange url with code in it :
Screenshot from 2024-07-17 15-37-00

Expected behavior

I’d like the image to be displayed, or at least a correct url

Failure Logs

Context

  • Project name: Certainty
  • Team name: Certainty
  • Environment name: Preprod
  • Agent technology: nodejs
  • "@forestadmin/agent": "1.38.12",
    
    @forestadmin/datasource-sequelize”: “1.8.1”,
    @forestadmin/plugin-aws-s3”: “1.3.72”,
  • Database type: pg

Hello @Quentin_Farizon, welcome to the community.
Can you please check directly in your database what does the data look like ? Is it only the aws url ? or do you have code as well ?
To me it looks like the code + url is stored in your database.
If this is the case, there might be an issue with the upload, rather than the list.

In the database I have the result of the storeAt function I provided :
image

Ok,
Did you configure anything in the widgets (edit and display) for the Logo field in the frontend ?
There are options to add prefixes for files in here, so that could be your issue.

Nothing configured no

Ok.

Could you try setting up a prefix using the widget file display config so that the frontend can access the image as the correct url ?

But without any widget configuration, why is it not returning the raw text ? Do you have some documentation on what the plugin-aws-s3 does on get/list ?

I have tried setting widget file with my prefix https://certainty-preprod.s3.eu-west-3.amazonaws.com

But it is adding it twice : https://certainty-preprod.s3.eu-west-3.amazonaws.com/https://certainty-preprod.s3.eu-west-3.amazonaws.com/public/VendorCompany/tLa9mbJqQhC0smOw.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIA2UC26O7DR4N2LMYF%2F20240718%2Feu-west-3%2Fs3%2Faws4_request&X-Amz-Date=20240718T150438Z&X-Amz-Expires=300&X-Amz-Signature=d2f465459bc7213bfa011833d7d298fb4f81eaec32a2795f9edc88be69dc5699&X-Amz-SignedHeaders=host&x-id=GetObject

I have tried disabling the customization with plugin-aws-s3, and the reading works fine now :

  • with widget text, I get the raw key path from my db
  • with widget file + prefix, my images are displayed

I believe I have found the root of the issue in the @forestadmin/plugin-aws-s3 package.
A fix is on the way.

1 Like

Thinking about it, it would make sense for me to presign url myself, in a model hook (I have plugged FA onto Sequelize), so that both ForestAdmin retrieval and standard retrieval have the same mechanism. In this context, maybe the plugin should have a readMode: ‘passthrough’ (or “ignore” ? or “bypass” ?) that sends the value as-is.

I’ve patched it, it works well !

Here is the patch :

diff --git a/node_modules/@forestadmin/plugin-aws-s3/dist/field/create-field.js b/node_modules/@forestadmin/plugin-aws-s3/dist/field/create-field.js
index 7bdd348..69ec1e2 100644
--- a/node_modules/@forestadmin/plugin-aws-s3/dist/field/create-field.js
+++ b/node_modules/@forestadmin/plugin-aws-s3/dist/field/create-field.js
@@ -17,6 +17,9 @@ function createField(collection, config) {
             key = config.objectKeyFromRecord?.mappingFunction
                 ? await config.objectKeyFromRecord.mappingFunction(record, context)
                 : key;
+            if (config.readMode === 'passthrough') {
+                return key
+            }
             if (config.readMode === 'proxy') {
                 return (0, data_uri_1.encodeDataUri)(await config.client.load(key));
             }
diff --git a/node_modules/@forestadmin/plugin-aws-s3/dist/types.d.ts b/node_modules/@forestadmin/plugin-aws-s3/dist/types.d.ts
index 253e95f..2d34023 100644
--- a/node_modules/@forestadmin/plugin-aws-s3/dist/types.d.ts
+++ b/node_modules/@forestadmin/plugin-aws-s3/dist/types.d.ts
@@ -64,7 +64,7 @@ export type Options<S extends TSchema = TSchema, N extends TCollectionName<S> =
      * dealing with small files and are behind an entreprise proxy which forbids direct
      * access to S3.
      */
-    readMode?: 'url' | 'proxy';
+    readMode?: 'url' | 'proxy' | 'passthrough';
     /**
      * Which ACL to use on the uploaded objects.
      * Default is "private" (urls will be signed so that the files can be reached from the frontend).

Hello @Quentin_Farizon,

I’m glad that you have found a solution that works for you.
If you need it, the fix for the plugin is live now.
Please mark this post as solved :pray:

Ok, the fix makes sense :slight_smile:
I may have to use passthrough or not, depending on the use case.

Would you consider adding passthrough mode in the library ? Maintaining a patch isn’t ideal, and I’m sure this would be useful for others (and easily documented)

Hello @Quentin_Farizon,

The @forestadmin/plugin-aws-s3 repository is open source: would you be willing to make a pull request with your suggestion ? It will be reviewed and integrated in mainline if ok.
Thanks !