简体   繁体   中英

Upload wav file and save in directory using python

Here is my db Model

     db.define_table('manage_music_file',                                                                                                           
     Field('action_is', requires=IS_IN_SET(('Insert', 
               'Remove')),notnull=True, default='Insert'),                                   
     Field('wav_file', 'upload', comment='Please upload your .wav 
                file',requires=IS_NOT_EMPTY()           
     )

This my controller

    def index(): 
       form = SQLFORM(db.manage_music_file)  
         #return dict(form=form)
       if form.process().accepted:
          logger.debug(('here we ahve a form',form))
          errors = []
          if form.vars['action_is'] == 'Insert':
             logger.debug(('where file need to place'))
             if not form.vars['wav_file']:
                  errors.append('No file given')
             return 'No file given'
          else:
            dirname='/var/lib/asterisk/sounds/musiconhold'
            logger.debug(('where file need to place', dirname))
            import os.path
            completeName = os.path.join(dirname, form.vars.wav_file)
            file1 = open(completeName, "a")
            file1.close()

       return dict(form=form)

I am sending wav file A.wav in upload But i am receiving file in this format in directory

      manage_music_file.wav_file.a70701e297ffec7a.412e776176.wav 

I want same name A.wav in directory as well

      A.wav 

Hamza,web2py将这些文件重命名为一种安全措施,以帮助防止目录遍历攻击。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM