4

I am using django-piston and curl to post file to specific phone numbers in my database. But I'm having problems uploading files.

This is my post response using 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'

Please help!

Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193
hassanadnan
  • 435
  • 3
  • 8
  • 17