【问题标题】:Django-piston file uploadingDjango-piston 文件上传
【发布时间】:2011-06-27 15:39:18
【问题描述】:

我正在使用 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'

请帮忙!

【问题讨论】:

    标签: file-upload curl django-piston


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-19
    • 1970-01-01
    • 2012-01-15
    • 2013-03-27
    • 2011-09-21
    • 2011-07-31
    • 2011-03-18
    相关资源
    最近更新 更多