adonisjs / drive-s3

S3 driver for AdonisJS drive
MIT License
21 stars 9 forks source link

Multiple errors in library usage, probably outdated #22

Closed leofmarciano closed 1 year ago

leofmarciano commented 1 year ago

None of the upload means available in the documentation work correctly

I recently tried to use this library within a clean, newly initialized adonisjs project. Using the means indicated by the documentation, I receive the following error:

[ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of File

The same error is overcome when enabling autoProcess: true, inside config/bodyparser.ts

However, it returns a TypeError each time the function is called:

TypeError: this.adapter.config.endpoint is not a function

If the autoProcess is set to false, I get null during file upload:

 let avatar = ctx.request.file('avatar')
 console.log(avatar)

null

My goal was to stream the file directly to S3 so that there was no need for state management within the application that works inside kubernetes If my usage is wrong, I apologize in advance.

Package version

"@adonisjs/drive-s3": "^1.3.2",

Node.js and npm version

node v18.16.0 npm v9.5.1

Sample Code (work well)

import Drive from '@ioc:Adonis/Core/Drive'
export class UploadFile {
  public async execute(filePath: string, contents: any) {
    try {
      await contents.moveToDisk(filePath, {}, 's3')
      return await Drive.use('s3').exists(filePath)
    } catch (error) {
      console.error(error)
      return error
    }
  }
}
leofmarciano commented 1 year ago

@thetutlage

thetutlage commented 1 year ago

What you need is to follow the Direct files upload guide.