Error updating the SharePoint columns in a Document Library when the filename is very long.
I am uploading a file to SharePoint successfully using the api, but when I come to set the data in the SharePoint columns I'm getting an error. This only happens when I have uploaded a file with a very long filename (around 180 characters). Files with short filenames work fine.
My code is quite simply :-
ctx=ClientContext('https://mycopmany.sharepoint.com/sites/MySite/').with_credentials(userCredentials)
SP_Location="TheLibrary/TheFolderWithaVeryLongName"
fileName="verylongfilename.pdf
path="../../path/verylongfilename.pdf"
with open(path, 'rb') as content_file:
fileContent=content_file.read()
targetFolderUrl=ctx.web.ensure_folder_path(SP_Location).execute_query()
targetFile=targetFolderUrl.upload_file(fileName,fileContent)
ctx.execute_query()
listItem=targetFile.listItemAllFields
listItem.set_property('COMMITTEE','SM_Team')
listItem.update()
ctx.execute_query()
After the file uploads successfully I get this error when setting the column data :-
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://SP_Location/fileName/listItemAllFields
However, if I try using a short filename, then it uploads the file, and sets the column data just fine. It only throws an error when the filename/location are around 180 characters.