使用 YUI3 将文件上传到 RESTful PUT url
我正在尝试使用 YUI3 将文件上传到 RESTful PUT url,但是当我在 io 的配置中将 upload 设置为 true 时,它将文件作为 POST 而不是 PUT 发送。如果我删除配置中的上传设置,我只会获取文件名,但它会转到 PUT url。我可以使用 PUT 来上传文件吗?还有其他方法可以做到这一点吗? 我假设这是 YUI3 的失败/错误,或者更确切地说是我对它的使用。
Form:
<form id='GFileForm' method='PUT' onSubmit='return false;'>
<input type='file' name='gfile' id='GFileName'>
<input type='submit' name='gfileupload' value='Upload' id='GFileUpload_Button'>
</form>
JS:
var cfg = {
method: "PUT",
form: {id: 'GFileForm', upload: true},
content_type: "multipart/form-data",
};
var request = Y.io(sUrl, cfg);
非常感谢任何帮助。
我还尝试找到有关使用 javascript 读取文件内容然后将其推入 PUT 数据的资源,但我似乎找不到任何相关内容。有谁知道这是否有可能?
干杯, 安迪.
I'm trying to upload a file to a RESTful PUT url with YUI3, but when I set upload to true in the config to io it sends the file as POST not PUT. If I remove the upload setting in the config I just get the filename, but it does go to the PUT url. Can I use PUT with a file upload? Is there another way to do this?
I'm assuming this is a failure/fault in YUI3 or rather my use of it.
Form:
<form id='GFileForm' method='PUT' onSubmit='return false;'>
<input type='file' name='gfile' id='GFileName'>
<input type='submit' name='gfileupload' value='Upload' id='GFileUpload_Button'>
</form>
JS:
var cfg = {
method: "PUT",
form: {id: 'GFileForm', upload: true},
content_type: "multipart/form-data",
};
var request = Y.io(sUrl, cfg);
Any help is here much appreciated.
I've also tried to find a resource on reading the file contents with javascript and then pushing that into the PUT data, but I can't seem to find anything about that. Does anyone know if that's a possiblilty?
Cheers,
Andy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PUT 不是发送表单数据的标准方式不幸的是,大多数网络浏览器不支持它。
PUT is not a standard way of sending form data and most web browsers don't support it, unfortunately.
检查这个例子。 https://github.com/chmouel/cors-swift-example
在此示例中,您可以看到我们如何将文件 PUT 到 RESTful PUT url。
Check this example. https://github.com/chmouel/cors-swift-example
In this example, you can see how we can PUT files to RESTful PUT url.