我最近问了另一个(相关的)问题,这导致了后续问题: 为输入表单提交数据而不是文件
阅读jQuery.ajax()文档(http://api.jquery.com/jQuery.ajax/),似乎可接受的dataTypes列表不包含图像。
我正在尝试使用jQuery.get(或必要时使用jQuery.ajax)来检索图像,将此图像存储在Blob中,然后在POST请求中将其上传到另一台服务器。当前,由于数据类型不匹配,我的图像最终被损坏(字节大小不匹配等)。
执行此操作的代码如下(它在coffeescript中,但应该不难解析):
handler = (data,status) ->
fd = new FormData
fd.append("file", new Blob([data], { "type" : "image/png" }))
jQuery.ajax {
url: target_url,
data: fd,
processData: false,
contentType: "multipart/form-data",
type: "POST",
complete: (xhr,status) ->
console.log xhr.status
console.log xhr.statusCode
console.log xhr.responseText
}
jQuery.get(image_source_url, null, handler)
我如何检索此图像作为斑点?