该 Qt错误报告 对于没有实现的XMLHttpRequest overrideMimeType方法(eyllanesc的注释链接指向我)表明对arraybuffers有一些支持。基于此并查看QQmlXMLHttpRequest源代码,我能够实现这一点。这是一个示例(我有一个包含我自己的Base64编码器,因为Qt.btoa不起作用):
import QtQuick 2.7 import ArcGIS.AppFramework 1.0 App { id: app width: 400 height: 640 Component.onCompleted: { var url = 'https://firebasestorage.googleapis.com/v0/b/christophereby-3733b.appspot.com/o/icon1.png?alt=media'; var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'arraybuffer'; xhr.onreadystatechange = function() { if (xhr.readyState === XMLHttpRequest.DONE) { if (xhr.status === 200) { var response = new Uint8Array(xhr.response); var raw = ""; for (var i = 0; i < response.byteLength; i++) { raw += String.fromCharCode(response[i]); } //FROM https://cdnjs.cloudflare.com/ajax/libs/Base64/1.0.1/base64.js function base64Encode (input) { var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; var str = String(input); for ( // initialize result and counter var block, charCode, idx = 0, map = chars, output = ''; str.charAt(idx | 0) || (map = '=', idx % 1); output += map.charAt(63 & block >> 8 - idx % 1 * 8) ) { charCode = str.charCodeAt(idx += 3/4); if (charCode > 0xFF) { throw new Error("Base64 encoding failed: The string to be encoded contains characters outside of the Latin1 range."); } block = block << 8 | charCode; } return output; } var image = 'data:image/png;base64,' + base64Encode(raw); img.source = image; } } } xhr.send(); } Image { id: img } }