-
Notifications
You must be signed in to change notification settings - Fork 22
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
Moving to filesystem breaks images due to extensions #5
Comments
Is there an estimate when this will be fixed? I'm going to use this script but I will try to wait until this gets sorted. Thank you. |
@jcatarino, I haven't had time to investigat/reproduce the issue yet, but it should be easy to fix, either we could remove the mime detection form the script, or set "extension" to "" during the dbupdate. |
thanks I will postpone this migration until I can test and change the script myself, as im prioritising other tasks atm. If I eventually do it, I will do a PR with it. |
My migration went ok. I commented these lines:
|
I hacked this together really quick to fix some of the issues we were having after the migration... it may be a bit overkill, but it solved all the cases we were having....
|
I have also experienced problems using this tool to migrate GridFS to FileStore. Some of the images simply doesn't appear as the URL for downloading doesn't work. I think I have worked out the issue. The entries/rows in the Doing this https://github.com/arminfelder/gridfsmigrate/blob/master/migrate.py#L111 does not seem to work, because it might set a suffix other than what the db expects to find. As a side note, it seems like (but I haven't confirmed it), that newer rocket chat versions does not use any file suffix any more. It only uses the # Put inside class Migrator
def fixFilenames(self, collection, basedir):
db = self.getdb()
uploadsCollection = db[collection]
uploads = uploadsCollection.find({}, no_cursor_timeout=True)
i = 0
for upload in uploads:
fileext = upload.get('extension') or None
fileid = upload['_id']
if not upload['complete']:
continue
# Get the real filename by looking for the last path element in 'path',
# if that file cannot be found, then we're using the ID.
fnames = upload['path'].split('/')
filename = fnames[-1]
if not os.path.isfile(os.path.join(basedir, filename)):
filename = fileid + '.' + fileext if fileext else fileid
# Ensure the file is present
fullfilename = os.path.join(basedir, filename)
if not os.path.isfile(fullfilename):
print(f"{filename}: No such file")
#print(upload)
continue
# Does the file have a suffix?
fsplit = filename.split('.')
if len(fsplit) > 1 and fsplit[-1]:
suffix = fsplit[-1]
else:
suffix = None
if suffix != fileext:
print("{filename}: Suffix mismatches database (expected {fileext})")
#print(upload)
continue
# Skip files without suffix
if not suffix:
continue
i += 1
print(f"{i}. Renaming {filename} to {fileid}")
# Rename file
os.rename(fullfilename, os.path.join(basedir, fileid))
# Update database
uploadsCollection.update_one({"_id": upload["_id"]}, { "$set": { "extension": '' } })
# Add this to the bottom of the file
if args.command == "renamefiles":
obj.fixFilenames("rocketchat_uploads", args.destination) |
Cool tool!
I just ran it to move files out of GridFS to the local file system. Some images worked, some images didn't work... I spent about a half hour looking at the differences from the working images and the broken images in the rocketchat_uploads collection, as well as on disk.
After uploading a fresh new file, I realized rocket.chat stored the file without an extension in the uploads folder. I tried moving an image I know was broken from image.png to just image, and it started working!
Here's a one liner to fix it.
The text was updated successfully, but these errors were encountered: