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

file.path is undefined #52

Open
Ivan-Feofanov opened this issue Oct 8, 2022 · 1 comment
Open

file.path is undefined #52

Ivan-Feofanov opened this issue Oct 8, 2022 · 1 comment

Comments

@Ivan-Feofanov
Copy link

I'm trying to use the local upload option but it doesn't work - I'm getting the error The "oldPath" argument must be of type string or an instance of Buffer or URL. Received undefined.

After searches, I found that the file I'm receiving in the upload method has no path property. Why it can happen and how can I fix it?

Provider:

class LocalProvider extends BaseProvider {
  constructor (options: LocalUploadOptions) {
    super(options.bucket)
    if (!fs.existsSync(options.bucket)) {
      throw new Error('No folder')
    }
  }

  public async upload (file: UploadedFile, key: string): Promise<any> {
    const filePath = this.path(key)

    await fs.promises.mkdir(path.dirname(filePath), { recursive: true })
    await fs.promises.rename(file.path, filePath)
  }

  public async delete (key: string, bucket: string): Promise<any> {
    await fs.promises.unlink(this.path(key, bucket))
  }

  // eslint-disable-next-line class-methods-use-this
  public path (key: string, bucket?: string): string {
    return `${path.join(this.bucket, key)}`
  }
}

Usage:

      resource: { model: dmmf.modelMap.HelpRequest, client: prisma },
      options: {
        properties: {
          image: { isVisible: false }
        }
      },
      features: [uploadFeature({
        provider: new LocalProvider({ bucket: 'public' }),
        properties: {
          key: 'image', // to this db field feature will safe S3 key,
          mimeType: 'mimeType' // this property is important because allows to have previews,
        },
        validation: {
          mimeTypes: ['image/png', 'image/jpg', 'image/jpeg']
        }
@GeekDenCode
Copy link

After a lot of research, I figured out that this is happening because the plugin doesn't even create the temporary file. And this happens because fastify has a different key in the attached files object, unlike express. I was at the beginning of development, so switching to express helped me, everything works fine on it with the same code.

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

No branches or pull requests

2 participants