-
Notifications
You must be signed in to change notification settings - Fork 52
Open
Description
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']
}
Metadata
Metadata
Assignees
Labels
No labels