virtualzone/onedrive-uploader

Add an Automatic Filename Normalizer (OneDrive Supported Filenames)

OttomanZ opened this issue · 2 comments

Hi,
I use this utility quite a lot and one thing I have noticed is that sometimes there are filenames that have characters like $.|, etc that cause this to give error:400, and when I remove those characters as suggested in Microsoft Graph API Docs, it uploads without an issue.

Another Important Issue

Required Changes for Illegal Characters

  • Removing White spaces in paths as follows, ./output/ something i like.pdf will not upload due to a while space before the name something. Where as this will upload ./output/something i like.pdf.
  • Trailing white spaces also cause issues such as ./output/something i like.pdf will not upload and hence it needs to be fixed.
  • Illegal Characters need to be removed, my implementation in python
    """
    Removes Illegal OneDrive Characters
    """

    correct_name = filename.split('/')[2]
    correct_name = correct_name.lstrip()
    # removing the illegal characters
    #  ~ " # % & * : < > ? / \ { | }
    correct_name = correct_name.replace('~', '')
    correct_name = correct_name.replace('"', '')
    correct_name = correct_name.replace('#', '')
    correct_name = correct_name.replace('%', '')
    correct_name = correct_name.replace('&', '')
    correct_name = correct_name.replace('*', '')
    correct_name = correct_name.replace(':', '')
    correct_name = correct_name.replace('<', '')
    correct_name = correct_name.replace('>', '')
    correct_name = correct_name.replace('?', '')
    correct_name = correct_name.replace('/', '')
    correct_name = correct_name.replace('\\', '')
    correct_name = correct_name.replace('{', '')
    correct_name = correct_name.replace('|', '')
    correct_name = correct_name.replace('}', '')

So, I think this should be No. 1 Priority in onedrive-uploader releases from now on.

@virtualzone I believe this Microsoft Support Page should be referenced here for a quick implementation for filename sanitation https://support.microsoft.com/en-us/office/restrictions-and-limitations-in-onedrive-and-sharepoint-64883a5d-228e-48f5-b3d2-eb39e07630fa

Hi @OttomanZ, thanks for this hint! I have implemented file and folder name sanitisation in version 0.8.