如何使用JQuery使用HTTP“PUT”上传文件?
我想使用JQuery-File-Upload上传文件,但使用HTTP“PUT”而不是multipart-forms。 根据他们的网站 :
- Multipart and file contents stream uploads: Files can be uploaded as standard "multipart/form-data" or file contents stream (HTTP PUT file upload).
但我在他们的文档中找不到如何做到这一点。 有人可以帮忙吗?
根据: https : //github.com/blueimp/jQuery-File-Upload/wiki/Options
方法
用于将文件发送到服务器的HTTP请求的方法。 可以是POST(multipart / formdata文件上传)或PUT(流文件上传)。 接受String或返回String的函数。
你应该使用:
$('#file_upload').fileUpload({ namespace: 'file_upload_1', url: '/path/to/upload/handler.json', method: 'PUT' });
我也喜欢REST,但您可能希望确保在需要支持的浏览器上进行unit testing。
http://api.jquery.com/jQuery.ajax/
要求的类型(“POST”或“GET”),默认为“GET”。 注意:此处也可以使用其他HTTP请求方法,例如PUT和DELETE,但旧版浏览器可能不支持这些方法。
请参阅此答案如何使用JQuery将数据输出到Rails