Skip to content

How do i replace a file in uploads but keep the path. #10608

Closed Answered by chrisAlwinYS
chrisAlwinYS asked this question in Q&A
Discussion options

You must be logged in to vote

If anyone comes across this and needs help, I have solved my issue using the beforeOperation and afterChange hooks. This is using a title field to generate the "slug" but it stays consistent. There's a possibility to make this a plugin to add to other documents should we need to...

    beforeOperation: [
      async ({ args, operation, req }) => {
        if (operation === 'create' || operation === 'update') {
          if (req?.file && args?.data?.title) {
            const files = req?.file
            if (files && files && files.name) {
              const fileExtension = files.name.split('.').pop() // Extract file extension
              const fileTitle = args?.data?.title.replace(/[^…

Replies: 1 comment

Comment options

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