def store_media_files(document, resource, original=None):
 for field in resource_media_fields(document, resource):
  if (original and (field in original)):
   if isinstance(original[field], list):
    for file_id in original[field]:
     app.media.delete(file_id, resource)
   else:
    app.media.delete(original[field], resource)
  if document[field]:
   if isinstance(document[field], list):
    id_lst = []
    for stor_obj in document[field]:
     id_lst.append(app.media.put(stor_obj, filename=stor_obj.filename, content_type=stor_obj.mimetype, resource=resource))
    document[field] = id_lst
   else:
    document[field] = app.media.put(document[field], filename=document[field].filename, content_type=document[field].mimetype, resource=resource)

def store_media_files ( document , resource , original = None ) : for field in resource_media_fields ( document , resource ) : if ( original and ( field in original ) ) : if isinstance ( original [ field ] , list ) : for file_id in original [ field ] : app . media . delete ( file_id , resource ) else : app . media . delete ( original [ field ] , resource ) if document [ field ] : if isinstance ( document [ field ] , list ) : id_lst = [ ] for stor_obj in document [ field ] : id_lst . append ( app . media . put ( stor_obj , filename = stor_obj . filename , content_type = stor_obj . mimetype , resource = resource ) ) document [ field ] = id_lst else : document [ field ] = app . media . put ( document [ field ] , filename = document [ field ] . filename , content_type = document [ field ] . mimetype , resource = resource )
store any media file in the underlying media store and update the document with unique ids of stored files .