Skip to content

How to use hooks to upload file to an ftp server #189

Answered by jmikrut
aljubaer asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @aljubaer

You're almost there! You have a bug in your hook, though.

Your if statement that is checking if the operation.req.headers.hook is equal to beforeChange is incorrect and unnecessary. Because you are adding a function to the beforeChange hooks array itself, you know that the code will only be running in a beforeChange context.

So basically, right now, code within your if will never fire. Just remove it!

Pro tip:

You might want to do different actions based on if your beforeChange hook is either running in response to a create or an update operation. You can gain access to which operation is active by destructuring operation out of the hook arguments, like so:

{
  beforeChange: 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by aljubaer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants