System Information
- Strapi Version: 3.6.8
- Operating System: Ubuntu 21.04
- Database: Postgresql 13.4 (Ubuntu 13.4-0ubuntu0.21.04.1)
- Node Version: 14.18.0
- NPM Version: 6.14.15
- Yarn Version: –
When uploading an image with a POST request such as the following in Python 3:
hds = {'Authorization': 'Bearer ' + auth_token}
endpoint = "http://localhost:1337/upload";
requests.post(endpoint, data={}, files=files, headers=hds)
The Strapi returns the following error:
error: insert into "upload_file_morph" ("field", "order", "related_id", "related_type", "upload_file_id") values ($1, $2, $3, $4, $5) returning * - invalid input syntax for type integer: "http://localhost:1337/uploads/image.jpg
at Parser.parseErrorMessage (/home/user/Apps/heroku/myapplication/node_modules/pg-protocol/dist/parser.js:287:98)
at Parser.handlePacket (/home/user/Apps/heroku/myapplication/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/home/user/Apps/heroku/myapplication/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket.<anonymous> (/home/user/Apps/heroku/myapplication/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (events.js:400:28)
at Socket.emit (domain.js:475:12)
at addChunk (internal/streams/readable.js:293:12)
at readableAddChunk (internal/streams/readable.js:267:9)
at Socket.Readable.push (internal/streams/readable.js:206:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
From previous event:
at Child.<anonymous> (/home/user/Apps/heroku/myapplication/node_modules/bookshelf/lib/model.js:1160:42)
From previous event:
at Child.<anonymous> (/home/user/Apps/heroku/myapplication/node_modules/bookshelf/lib/model.js:1159:14)
at processImmediate (internal/timers.js:464:21)
From previous event:
at Child.<anonymous> (/home/user/Apps/heroku/myapplication/node_modules/bookshelf/lib/model.js:1060:10)
From previous event:
at addRelationMorph (/home/user/Apps/heroku/myapplication/node_modules/strapi-connector-bookshelf/lib/relations.js:29:36)
at /home/user/Apps/heroku/myapplication/node_modules/strapi-connector-bookshelf/lib/relations.js:339:24
at Array.map (<anonymous>)
at /home/user/Apps/heroku/myapplication/node_modules/strapi-connector-bookshelf/lib/relations.js:338:28
at async Promise.all (index 0)
at async Function.update [as updateRelations] (/home/user/Apps/heroku/myapplication/node_modules/strapi-connector-bookshelf/lib/relations.js:368:5)
The expected behaviour would be for strapi-connector-bookshelf to match the ID, be it integer or string, without problems with its column type.
In file relations.js
at line 324
const currentValue = transformToArrayID(params.values[current]);
params.values[current]
returns a String with a URL and fails when mapping params for addRelationMorhp()
. This variable ‘id’ is asigned in ‘upload_file_morph’ table to ‘upload_file_id’ columns which expected an integer.
I put a dirty fix in development, replacing:
const currentValue = transformToArrayID(params.values[current]);
with:
const currentValue = transformToArrayID(params.id);
My project is small and i think this could be enough. However, this changes the code of a node module and is not a solution for production and even less so for Heroku deployment.
What might be some solutions?