I can't get file upload to work. it wont return file object


#1

This way i can see the images in my windows temp folder with extension .tmp

async image ({ request, response }) {
    const image = request.file('file', {
      maxSize: '20mb',
      allowedExtensions: ['jpg', 'png', 'jpeg']
    })

    const fileName = `${new Date().getTime()}.${image.extension()}` // image.extension() is not a function
  }

When i try to access image.extension() or image.fileName i get error and null and so on.

Also tried this, in this version the file gets moved into s3 but with name null ofcorse cause fileName returns null.

     request.multipart.file('file', {}, async (file) => {
        await Drive.disk('s3').put('product/' + file.fileName, file.stream) // file.fileName returns null
     })

    await request.multipart.process()

The problem is that it seems it font return file object, i can’t access fileName and extension() etc… like docs say i should.


#2

Can u please take the pain to atleast remove the commented code?


#3

Also your example shows that you are mixing 2 strategies at once.

  1. Try to manually process the stream
  2. Also calling request.file which is only available when manual processing is turned off.

So please share

  1. What you want to do?
  2. And error or exceptions you have received

#4

I left the unncommented code cause i tryed this way also.

I have tried to turn autoprocessing off, and i have tried to read 4.0 docs and even older version.

Im just trying to save an image to some tmp folder with random name.

And process goes on like this.

When user saves product i will grab the tmp images -> rename them -> and move to S3 (Or should i move them right away to amazon tmp folder)

EDIT: Also made my first topic cleaner.


#5

With the new file upload implement in v4: to get the extension of the file, use image._subtype. FileName will return null by default, try image._clientName to get the name of the file as uploaded.

PS: Next time try showing the exact errors or exceptions you encounter when creating a thread as this will help us understand the problem and provide solutions.