Skip to content

Conversation

jitli98
Copy link

@jitli98 jitli98 commented Mar 3, 2020

I did the file uploads on Express but I've yet to figure out how exactly I should store them in the PostgreSQL database. Will definitely look into it the next few days.

@vedantroy
Copy link
Collaborator

vedantroy commented Mar 7, 2020

@jitli98 For inserting a file into postgres, look at this: https://dba.stackexchange.com/questions/1742/how-to-insert-file-data-into-a-postgresql-bytea-column

The mentioned postgres function (probably pg_read_file) isn't supported by knex.js. You will have to use knex.raw to manually write the necessary SQL.

For inserting files into the postgres DB, I would recommend searching for "postgres insert file into database" rather than searching about knex.js because the end result is going to be a raw SQL query that you will just execute using knex.raw(some string)

@jitli98 jitli98 closed this Mar 10, 2020
@jitli98 jitli98 reopened this Mar 10, 2020
@jitli98
Copy link
Author

jitli98 commented Mar 10, 2020

Completed the integration of Postgres into file uploads.
I've also included instructions for setting up file table in the migration file.
Let me know if you want me to include those instructions in the README instead.

Copy link
Collaborator

@vedantroy vedantroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completed the integration of Postgres into file uploads.
I've also included instructions for setting up file table in the migration file.
Let me know if you want me to include those instructions in the README instead.

Add the instructions for running all migrations with npm run knex migrate:latest, or whatever the command should be to the README.

@vedantroy
Copy link
Collaborator

I'm getting a "MulterError: Unexpected field". Do you have an idea of what the issue might be?

@jitli98
Copy link
Author

jitli98 commented Mar 12, 2020

When u do a POST request on POSTMAN, make sure to include a field name when attaching file. In this case, the field name is 'myfile'.
I'll include a screenshot of post request on Slack.

@jitli98
Copy link
Author

jitli98 commented Mar 12, 2020

Fixed the aforementioned issues.

@jitli98 jitli98 force-pushed the gerry/file-upload branch 2 times, most recently from 5d4c51a to f199cfa Compare March 13, 2020 16:51
@vedantroy
Copy link
Collaborator

Sorry this is taking so long. I'll be more prompt about reviewing future PRs. One more request:

  • Change the route to "/files//upload". I think files/uploadfile/<user> is a bit redundant.

@jitli98
Copy link
Author

jitli98 commented Mar 19, 2020

You want me to remove the user query parameter as well?

@jitli98 jitli98 force-pushed the gerry/file-upload branch from f199cfa to 29262d1 Compare March 19, 2020 22:27
@vedantroy
Copy link
Collaborator

@jitli98 Yeah. If the user is in the route, then it shouldn't have to be in a query parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants