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

Files.load -> options.fileName is not in filepath #875

Open
Gobliins opened this issue Jun 26, 2023 · 2 comments
Open

Files.load -> options.fileName is not in filepath #875

Gobliins opened this issue Jun 26, 2023 · 2 comments

Comments

@Gobliins
Copy link

Hello again,

I use the Files.load(url, options) to read and store data.
Inside the DB the filenames are saved correctly and the path to the FS. But when looking inside the directory i only get something like that:

UUID-original-UUID.<ext> -> ../files/76gd9asd8za-orignal-8jdc1hd8.png

I was wondering how this is generated, It's logical that there are UUIDs so no files will be overwritten, but can I somehow modify the generated path / filename as well?

Like UUID-original-filename.<ext> -> ../files/76gd9asd8za-orignal-image.png

Here's my code:

  const options = {
    fileName: newFileName, // image.png for example
    type: fileType,
    meta: {
      oldId: fileObj._id,
      source: 'import',
      collection: 'attachments',
    },
    userId,
    size: fileSize,
  };

  Files.load(loadUrl, options,
      (loadError, fileRef) => {
        if (loadError) {
          return reject(loadError);
        } else {
          return resolve(fileRef);
        }
      }, true);

Regards

@dr-dimitru
Copy link
Member

Hello @Gobliins ,

Please take a look on namingFunction option passed to Files Constructor, it should solve your needs.

Feel free to close it in case if the issue is solved on your end.

@Gobliins
Copy link
Author

Hey thx @dr-dimitru

Got it! Works fine 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants