Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultipartFile helper’s moveToDisk method does not add writeOptions #54

Closed
kamilcglr opened this issue Sep 25, 2024 · 3 comments · Fixed by #55
Closed

MultipartFile helper’s moveToDisk method does not add writeOptions #54

kamilcglr opened this issue Sep 25, 2024 · 3 comments · Fixed by #55

Comments

@kamilcglr
Copy link
Contributor

kamilcglr commented Sep 25, 2024

Package version

3.2.0

Describe the bug

Hello,

Context:
I am using Adonis 6.14.0 with the drive plugin 3.2.0.
I am uploading a file and validating it with the included validator.
I have a drive disk that is an S3 bucket.

When I try to move the file using the MultipartFile helper while providing the drive key and adding metadata for AWS, it seems that the metadata is being ignored.

Possible cause:
I looked at the source code and it seems that when the diskNameOrOptions is provided, the writeOptions are ignored.(

let diskName: string | undefined
let options: WriteOptions | undefined
if (typeof diskNameOrOptions === 'string') {
diskName = diskNameOrOptions
} else if (diskNameOrOptions && !writeOptions) {
options = diskNameOrOptions
} else if (writeOptions) {
options = writeOptions
}
const disk = diskName ? drive.use(diskName) : drive.use()
return disk.moveFromFs(this.tmpPath, key, options)
)

Am I right ?

Here is an example

const metadata = {
          invoice_internal_reference_type: 'Autre',
          invoice_internal_reference: '',
          invoice_account_number: '',
          invoice_account_type: '',
          invoice_source_incident_caseid: '',
}
        
await payload.file.moveToDisk(
      `${new Date().getFullYear()}/${fileName}`,
      's3Drive',
      {
        Metadata: metadata,
      }
    )

But when I use the drive directly, it works. The metadata is passed to the AWS command and is visible in the bucket

await drive
      .use('s3Drive')
     .moveFromFs(new URL(payload.file.tmpPath!, import.meta.url), `${new Date().getFullYear()}/${fileName}`, {
      Metadata: metadata,
      })

Thank you in advance.

Reproduction repo

No response

@kamilcglr kamilcglr changed the title MultipartFile helper moveToDisk does not add writeOptions MultipartFile helper’s moveToDisk method does not add writeOptions Sep 25, 2024
@thetutlage
Copy link
Member

Can you please run your application using NODE_DEBUG="flydrive:*" npm run dev and share the logs from the FlyDrive. Make sure to use the bodyparser API while debugging

@kamilcglr
Copy link
Contributor Author

kamilcglr commented Sep 25, 2024

Can you please run your application using NODE_DEBUG="flydrive:*" npm run dev and share the logs from the FlyDrive. Make sure to use the bodyparser API while debugging

Here are the logs

FLYDRIVE:S3 68581: driver config {
  credentials: 'REDACTED',
  region: 'eu-west-1',
  bucket: 'my-s3-bucket',
  visibility: 'private'
}
FLYDRIVE:CORE 68581: creating disk instance for service s3Drive
FLYDRIVE:S3 68581: creating/updating file my-s3-bucket:invoicesFromSupplier/2024/1234_f3e1ea6c-8565-4f56-bbb6-722a939f1d00.pdf
FLYDRIVE:S3 68581: setting "invoicesFromSupplier/2024/1234_f3e1ea6c-8565-4f56-bbb6-722a939f1d00.pdf" file's content-type to "application/pdf"
FLYDRIVE:S3 68581: s3 write options {
  Bucket: 'my-s3-bucket',
  ACL: 'private',
  ContentType: 'application/pdf'
}

@thetutlage
Copy link
Member

Ohh yes. I see there is an error with the logic of using options. Can you please create a PR with the fix?

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 a pull request may close this issue.

2 participants