-
Hi guys, I'm trying to upload files with FlyDrive and i'm having some issues. await Promise.all(
payload.photos.map(async (item) => {
const driver = env.get('NODE_ENV') === 'production' ? 's3' : 'fs'
const source = `${item.tmpPath}.${item.extname}`
const file = source.split('/').at(-1)
const destination = `photos/${file}`
await drive.use(driver).copyFromFs(source, destination)
await profile.related('photos').create({ url: destination })
})
) The upload happened but the uploaded files are empty |
Beta Was this translation helpful? Give feedback.
Answered by
ekimkael
Jul 29, 2024
Replies: 1 comment
-
I found the solution and below are the explanations: await Promise.all(
payload.photos.map(async (item) => {
const driver = env.get('DRIVE_DISK') as any
const source = `${item.tmpPath}.${item.extname}`
const file = source.split('/').at(-1)
const destination = `photos/${file}`
/**
* you just have to pass the temporary path
* files in the temporary folder have no extension, because:
*
* 1. Security: Temporary files are typically created without extensions to prevent
* accidental or malicious execution based on file type.
*
* 2. Uniqueness: Temporary filenames are generally generated to be unique, often
* using random identifiers or time-based names, without concern for extensions.
*
* 3. Flexibility: This approach allows the system to handle all file types in the
* same manner, without making assumptions based on file extensions.
*
*/
await drive.use(driver).moveFromFs(item.tmpPath!, destination)
await profile.related('photos').create({ url: destination })
})
) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ekimkael
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found the solution and below are the explanations: