0

I have a collection in MongoDB stores users' resumes, and they are stored as:

enter image description here

I've tried use python to convert it with this post, but the generated file cannot be viewed as pdf file.

The python code has:

import base64, os
from pymongo import *

client = MongoClient("mongodb://localhost:27017/")
db = client.local
collection = db.users


ppl = collection.find({
    "_id": "38M8GoJS57Tp9MsGM"
})[0]

bindata = ppl["profile"]["resume"]

with open(os.path.expanduser('~/Desktop/test.pdf'), 'wb') as fout:
     fout.write(base64.decodestring(bindata))

I wonder what I should do.

Yuze Ma
  • 357
  • 1
  • 9

1 Answers1

1

I solved it by directly changing

fout.write(base64.decodestring(bindata))

to

 fout.write(bindata)

Because binary data can get wrote in directly

Yuze Ma
  • 357
  • 1
  • 9