如何从FilePicker获取[object file],例如来自< input type = file>对于XHR POST请求? [英] How to get an [object File] from FilePicker like from <input type=file> for XHR POST Request?
问题描述
再次问好,现在我需要一个来自FilePicker的[object File]来通过XHR Post Request发送它。
一个带< input type = file>的解决方案有效,但WinRT的FilePicker会更好 由于我需要一个仅限图像的缩略图视图。
< span style ="white-space:nowrap">解决方案是
Hello again, now I need an [object File] from FilePicker to send it via XHR Post Request.
A solution with <input type=file> works, but it'll be better with WinRT's FilePicker due to I need an image-only thumbnail view.
The solution is
input.addEventListener("change", function () {
var file = this.files[0];<span style="font-family:arial,sans-serif; font-size:x-small"><span style="white-space:nowrap"><br/>formdata.append("photo", file);
log('file: ' + file)
var fd = new FormData();
fd.append('photo', file);
var xhr = new XMLHttpRequest();
MethodWithNoParametrs('photos.getWallUploadServer').then(function (result) {
xhr.open('POST', JSON.parse(result.responseText).response.upload_url + '&access_token=' + vk.Token);
xhr.send(fd);
xhr.onload = function () {
var json = JSON.parse(xhr.responseText);
log(xhr.responseText);
log(xhr.statusText);
Method('photos.saveWallPhoto?server=' + json.server + '&photo=' + json.photo + '&hash=' + json.hash).then(function (result) {
log(result.responseText);
Method('wall.post?attachment='+JSON.parse(result.responseText).response[0].id).then(function (result) {
log(result.responseText);
}, function (err) {
log(err);
});
})
}
});</span></span>
推荐答案
嗨Moushen,
Hi Moushen,
我不知道是什么你要的是。 选择器会返回文件对象。
I am not sure what you are asking for. The Pickers do return file object.
如果您询问如何使用XHR上传服务器的特定格式,则需要了解该格式是什么。 实现这一目标的最佳方法是使用成功案例并将其与XHR案例进行比较。 您可以使用工具
(如fiddler( http://fiddler2.com )来检查HTTP流量并查看您的差异是什么。
If you are asking how to use XHR to upload a particular format for your server, you will need to understand what that format is. The best way to accomplish this is to use a successful case and compare that to the XHR case. You can use a tool like fiddler (http://fiddler2.com) to inspect the HTTP traffic and see what your differences are.
-Jeff
这篇关于如何从FilePicker获取[object file],例如来自< input type = file>对于XHR POST请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!