file-upload - Django活塞文件上传

标签 file-upload curl django-piston

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

处理程序.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 - Django活塞文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5004853/

相关文章:

javascript - 使用 fetch 返回的结果与使用 curl 或在浏览器中打开页面的结果不同

python - 活塞自定义响应表示

python - 值错误 : Cannot assign in django

swift - 使用 Swift 3 和 Amazon SDK 显示图像上传到 Amazon S3 的上传进度

amazon-s3 - 上传图像 - 数据显示为 "���"�!1A"Qaq�2�B�#"并且图像为空白 - Next.js 应用程序上传到 DigitalOcean Spaces/AWS S3

asp.net - 如何在 ASP.NET Core 中进行这样的文件上传?

java - Spring Framework是否支持多部分请求中的流模式

python - 如何在 linux 终端中使用 '$' 输入 sftp 密码

curl - 亚马逊EC2实例无法解析主机

python - Django-Piston 中的错误处理