How to save the data in mongoDB using gridFS

Solution for How to save the data in mongoDB using gridFS
is Given Below:

I want to save my data in mongoDB using gridFS (because my documents are larger than 16MB), I used the instructions below :

”’
clss=[dict(dataPreparation.loc[k])] # the type of dataPreparation is dataFrame (we recover one line of dataFrame)

df=pd.DataFrame(clss)

file=df.to_excel(“dataPreparation.xlsx”) # save my data into excel file

datapre=open(“dataPreparation.xlsx”,’r’)

fs.put(datapre.read(),_id=”class:”+str(k+1),n=k+1) # save the data in mongoDB ”’
But I got this error:

UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0x8f in position 22: invalid start byte