veliovgroup / Meteor-Files

🚀 Upload files via DDP or HTTP to ☄️ Meteor server FS, AWS, GridFS, DropBox or Google Drive. Fast, secure and robust.
https://packosphere.com/ostrio/files
BSD 3-Clause "New" or "Revised" License
1.11k stars 166 forks source link

What defines the filename of the saved file? #863

Closed twentyfortysix closed 1 year ago

twentyfortysix commented 1 year ago

I'm having an issue:

I can't figure out the logic behind file naming, sometimes it is file ID, sometimes file name sometimes who knows what. METEOR@1.9.3 ostrio:files@1.14.3

Client and Server related

Description of the problem: After the years on meteor I try to migrate the content to other system. When I try to export media and import them back to new CMS I can't figure out how to locate the correct files with what I see in the database and is in reality on the disk.

here is a specific image record:


{
    "_id" : "249wvKAcn28eh9XvS",
    "name" : "antonin_jirat_-_stan.jpg",
    "extension" : "jpg",
    "path" : "/data/11159_antonin_jirat_-_stan.jpg",
    "meta" : {
        "width" : NumberInt(800),
        "height" : NumberInt(536)
    },
    "type" : "image/jpg",
    "size" : NumberInt(35739),
    "userId" : "Jo4CoqtwZjx5P5g8D",
    "versions" : {
        "original" : {
            "path" : "/data/11159_antonin_jirat_-_stan.jpg",
            "size" : NumberInt(35739),
            "type" : "image/jpg",
            "extension" : "jpg",
            "meta" : {
                "width" : NumberInt(800),
                "height" : NumberInt(536)
            }
        },
        "thumbnail" : {
            "path" : "/data/thumbnail-249wvKAcn28eh9XvS.jpg",
            "size" : NumberInt(6340),
            "type" : "image/jpg",
            "extension" : "jpg",
            "meta" : {
                "width" : NumberInt(419),
                "height" : NumberInt(281)
            }
        }
    },
    "_downloadRoute" : "/data",
    "_collectionName" : "Images",
    "isVideo" : false,
    "isAudio" : false,
    "isImage" : true,
    "isText" : false,
    "isJSON" : false,
    "isPDF" : false,
    "_storagePath" : "/data/11159_antonin_jirat_-_stan.jpg"
}

first thing what you see is that thumbnails have different naming pattern, once the file name is used once the ID. What is the difference between "path" and "_storagePath", they are same , sometimes differ?

Now when I check the folder with images the real image name is hard to guess it might be a ID or name related.. what I do use now is the "path" value but I'm not sure if that is the correct value I should be using in the migration process. When I use "path" I'm able to locate and find some of the files, not all though. The "path" does not seems to be always right, as when I try to find the file by name or ID sometimes I cannot find it amongst the static data. It is just not there, yet the app shows it as it can be seen from the link/s, like this one: https://jlbjlt.net/data/Images/249wvKAcn28eh9XvS/original/249wvKAcn28eh9XvS.png https://jlbjlt.net/data/Images/249wvKAcn28eh9XvS/original/249wvKAcn28eh9XvS.jpg https://jlbjlt.net/data/Images/249wvKAcn28eh9XvS/original/249wvKAcn28eh9XvS.pdf // ?¿ (see the file type does not matter, how come ?¿)

That is the same image from the json above.. see different names based on the attachment ID.. I guess the name here is just a dynamic route path that gas nothing to do with the real location of the file, little bit too dynamic to my taste. This is how I made the attachment path at that time when I made the app

Meteor.settings.public.siteUrl + obj._downloadRoute + '/' + obj._collectionName + '/' + obj._id + '/' + size + '/' + obj._id + '.' + obj.extension;

But again, what is the real location of the file, meaning what value in the db record I can trust that points to a real file on the disk? Because there is no such file on the disk as /data/antoninjirat-_stan.jpg or /data/249wvKAcn28eh9XvS.jpg(png, ..) yet the picture is served out to client on https://jlbjlt.net/data/Images/249wvKAcn28eh9XvS/original/249wvKAcn28eh9XvS.png.

twentyfortysix commented 1 year ago

I know, why.. some data are executables.

meaning they are not 2Ww9X6ZNEp3jXuPCd.png but ./2Ww9X6ZNEp3jXuPCd.png

Why some of the static data are saved as executables while others are not. I don't know. At least now I know that the files exists.

If you have large files and need them to be regular files again:

# check their executables (if you have a looong list of files)
find . -type f -perm -u+x -ls 
#make them normal again
find . -type f -perm -a=x

you might play with permissions a bit afterwards. This drove me nuts for days.

dr-dimitru commented 1 year ago

Hello @twentyfortysix

I see this issue is closed, so here's couple of things for your reference:

  1. Default naming function names file after fileId
  2. Control behaviour of naming function via setting namingFunction hook on FilesCollection definition
  3. For changing how file named during download use interceptDownload hook
  4. See how files named upon download by default here

hope that helps