new_contents: import datetime
  
  import gridfs
  import pymongo
  
  from scrapy.utils.misc import md5sum
  
  
  class GridFSFilesStorage(object):
      """MongoDB GridFS storage.
      Store files in GridFS and returns their ObjectId.
      Check if file exists based on file guid generated by pipeline"""
  
      def __init__(self, uri):
          client = pymongo.MongoClient(uri)
          self.db = client.myscrapy
          self.fs = gridfs.GridFS(self.db)
  
      def persist_file(self, file_guid, buf, info, meta=None, headers=None):
          """Save the file to GridFS and return it's ObjectId"""
  
          grid_id = self.fs.put(buf, scrapy_guid=file_guid)
          return grid_id
  
      def stat_file(self, file_guid, info):
          """Check if file exists based on file guid generated by the scrapy pipeline"""
  
          pdf = self.fs.find_one({'scrapy_guid': file_guid})
          epoch = datetime.datetime.utcfromtimestamp(0)
          last_modified = (pdf.upload_date - epoch).total_seconds()
          checksum = md5sum(pdf)
          return {'last_modified': last_modified, 'checksum': checksum, 'mongo_objectid': pdf._id}
  
subject: create GridFSFilesStorage