上传文件到bcs上,问题是上传文件名是中文和纯数字就报错,字母加数字没问题。
想不通。
中文:ascii' codec can't encode characters in position 9-11: ordinal not in range(128)
数字:'utf8' codec can't decode byte 0x9c in position 140: invalid start byte
谢谢!
def upfile(request):
global BUCKET,bcs
if request.method == 'GET':
return render_to_response('upload.html')
elif request.method == 'POST':
file = request.FILES['cs']
f = handfile(file)
b = bcs.bucket(BUCKET)
name = '/%s' % file.name
o = b.object(name)
o.put_file(f)
os.remove(f)
return HttpResponseRedirect('/p/')
def handfile(f):
fpath = '/tmp/%s' % f.name
with open(fpath,'wb+') as info:
for chunk in f.chunks():
info.write(chunk)
return fpath