XMLHttpRequest 事件侦听器无法在 Edge 上工作
XMLHttpRequest Event Listeners not Working on Edge
S3Upload.prototype.uploadToS3 = function(file, url, public_url, opts) {
var this_s3upload, type, xhr;
this_s3upload = this;
type = opts && opts.type || file.type;
xhr = this.createCORSRequest('PUT', url);
if (!xhr) {
this.onError('CORS not supported');
} else {
xhr.onload = function() {
if (xhr.status === 200) {
this_s3upload.onProgress(100, 'Upload completed.', public_url, file);
return this_s3upload.onFinishS3Put(public_url, file);
} else {
return this_s3upload.onError('Upload error: ' + xhr.status, file);
}
};
xhr.onerror = function() {
return this_s3upload.onError('XHR error.', file);
};
xhr.upload.onprogress = function(e) {
var percentLoaded;
if (e.lengthComputable) {
percentLoaded = Math.round((e.loaded / e.total) * 100);
return this_s3upload.onProgress(percentLoaded, (percentLoaded === 100 ? 'Finalizing.' : 'Uploading.'), public_url, file);
}
};
}
xhr.setRequestHeader('Content-Type', type);
xhr.setRequestHeader('x-amz-acl', 'public-read');
return xhr.send(file);
};
我正在使用此脚本将文件上传到 S3,它是 https://github.com/tadruj/s3upload-coffee-javascript 的一部分。一些功能参数已略有更改,但除此之外是相同的脚本。上传本身工作正常,但是当文件在 Edge 中上传时,进度不会更新。当我上传文件时,它保持在 0%,然后一旦完成就跳到 100%,中间没有任何东西。这在 Chrome 或 Firefox 中不是问题。
据我所知,问题似乎出在代码中
xhr.upload.onprogress = function(e) {
var percentLoaded;
if (e.lengthComputable) {
percentLoaded = Math.round((e.loaded / e.total) * 100);
return this_s3upload.onProgress(percentLoaded, (percentLoaded === 100 ? 'Finalizing.' : 'Uploading.'), public_url, file);
文件上传进度的事件侦听器未触发,调试器似乎证实了这一点。这可能是什么问题?
根据这个 https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12224510/,看起来这只是某些版本的 Edge 的问题。此问题已在 EdgeHTML 版本 18.17763 中修复。
S3Upload.prototype.uploadToS3 = function(file, url, public_url, opts) {
var this_s3upload, type, xhr;
this_s3upload = this;
type = opts && opts.type || file.type;
xhr = this.createCORSRequest('PUT', url);
if (!xhr) {
this.onError('CORS not supported');
} else {
xhr.onload = function() {
if (xhr.status === 200) {
this_s3upload.onProgress(100, 'Upload completed.', public_url, file);
return this_s3upload.onFinishS3Put(public_url, file);
} else {
return this_s3upload.onError('Upload error: ' + xhr.status, file);
}
};
xhr.onerror = function() {
return this_s3upload.onError('XHR error.', file);
};
xhr.upload.onprogress = function(e) {
var percentLoaded;
if (e.lengthComputable) {
percentLoaded = Math.round((e.loaded / e.total) * 100);
return this_s3upload.onProgress(percentLoaded, (percentLoaded === 100 ? 'Finalizing.' : 'Uploading.'), public_url, file);
}
};
}
xhr.setRequestHeader('Content-Type', type);
xhr.setRequestHeader('x-amz-acl', 'public-read');
return xhr.send(file);
};
我正在使用此脚本将文件上传到 S3,它是 https://github.com/tadruj/s3upload-coffee-javascript 的一部分。一些功能参数已略有更改,但除此之外是相同的脚本。上传本身工作正常,但是当文件在 Edge 中上传时,进度不会更新。当我上传文件时,它保持在 0%,然后一旦完成就跳到 100%,中间没有任何东西。这在 Chrome 或 Firefox 中不是问题。
据我所知,问题似乎出在代码中
xhr.upload.onprogress = function(e) {
var percentLoaded;
if (e.lengthComputable) {
percentLoaded = Math.round((e.loaded / e.total) * 100);
return this_s3upload.onProgress(percentLoaded, (percentLoaded === 100 ? 'Finalizing.' : 'Uploading.'), public_url, file);
文件上传进度的事件侦听器未触发,调试器似乎证实了这一点。这可能是什么问题?
根据这个 https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12224510/,看起来这只是某些版本的 Edge 的问题。此问题已在 EdgeHTML 版本 18.17763 中修复。