示例#1
0
 def selleraddCpinOk_view(self):
     request = self.request
     sid = self.request.params['sid']
     price = self.request.params['price']
     caiName = self.request.params['caiName']
     pic = self.request.params['pic']
     if not pic.name:
         return {'error': u'请选择文件后再上传'}
     file = pic.file
     ext = pic.filename.split('.').pop()
     # ../这样的目录却发现文件上传到workspace目录下,于是就出现了如下的目录结构
     save_path = '../canyin/canyin/upload/'
     save_path = PROJECT_PATH + '/static/upload/'
     print save_path
     date_time = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
     print date_time
     new_file = (date_time + '.' + ext.lower())
     destination = open(save_path + new_file, 'wb+')
     while True:
         data = file.read(2 << 16)
         if not data:
             break
         destination.write(data)
     destination.close()
     # 上传成功后将数据保存到数据库
     picPath = '../static/upload/' + new_file
     print picPath
     params = {'sid': sid, 'price': price, 'caiName': caiName, 'pic': date_time}
     Seller.sellerAdd(self.mongodb, **params)
     return {'one': 'yes'}