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 :
Expected behavior
I’d like the image to be displayed, or at least a correct url
Failure Logs
Context
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 :
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.
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 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
Ok, the fix makes sense
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 !