简体   繁体   English

jQuery.ajax和图像数据编码

[英]jQuery.ajax and image data encoding

I'm trying to fetch an image stored at S3, via AJAX, which has been uploaded using InkFilePicker. 我正在尝试通过AJAX提取存储在S3上的图像,该图像已使用InkFilePicker上传。 InkFilePicker has a method called filepicker.read() which can be used to read the raw data from an image. InkFilePicker具有一个称为filepicker.read()的方法,该方法可用于从图像读取原始数据。 However, it's quite limited so I want to use jQuery.ajax() instead. 但是,它非常有限,因此我想改用jQuery.ajax()。 But it seems that they don't return exactly the same data. 但是似乎它们没有返回完全相同的数据。

The data received when using filepicker.read() looks like this when logging it to the console: 使用filepicker.read()接收到的数据记录到控制台时如下所示:

来自filepicker.read()的数据

When using jQuery.ajax() it looks like this: 当使用jQuery.ajax()时,它看起来像这样:

来自jQuery.ajax()的数据

When using the data returned by jQuery.ajax() my other scripts seems to break (I'm extracting the EXIF data). 当使用jQuery.ajax()返回的数据时,我的其他脚本似乎坏了(我正在提取EXIF数据)。

So, why does it look different at all? 那么,为什么看起来根本不一样? Does jQuery try to encode/decode the data somehow? jQuery是否尝试以某种方式对数据进行编码/解码? Can I prevent that? 我可以预防吗?

Ok, I had to add this to override the mimetype for some reason... 好的,出于某种原因,我必须添加它以覆盖mimetype ...

$.ajax({
...
  beforeSend: function(xhr) {
      xhr.overrideMimeType( "text/plain; charset=x-user-defined" )
  }
...
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM