我正在使用django-piston和curl将文件发布到我的数据库中的特定电话号码。 但我在上传文件时遇到了问题。
这是我使用curl的帖子回复:
C:\curl>curl -F "phone_number=03219455375" -F "file=@C:/file.txt"
http://localhost:8000/api/uploadfile.json
Piston/0.2.2 (Django 1.2.4) crash report:
Method signature does not match.
Resource does not expect any parameters.
Exception was: 'InMemoryUploadedFile' object is not subscriptable
Handler.py:
if request.POST:
phone_number=request.POST['phone_number']
file_name=request.FILES['file']
if(phone_number == ""):
return rc.BAD_REQUEST
else:
upload2folder = os.path.join(UPLOAD_ROOT,phone_number)
if os.path.exists(upload2folder):
print "Heloo'"
open(os.path.join(upload2folder, file_name),
'wb').write(file_name.)
else:
os.mkdir(upload2folder)
#open(os.path.join(upload2folder, file_name),
'wb').write(file_name.file.read())
return rc.CREATED
else:
return rc.BAD_REQUEST'
请帮忙!
答案 0 :(得分:4)