看着 http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3/ManagedUpload.html#constructor-property
var upload = new AWS.S3.ManagedUpload({
params: {Bucket: 'bucket', Key: 'key', Body: stream}
});
Body假设是stream
。如果我想在浏览器中使用此stream
,如何从本地文件创建ManagedUpload
?
stream
与streamObject
uploadPart
不同
Body: new Buffer('...') || 'STRING_VALUE' || streamObject,
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#uploadPart-property
答案 0 :(得分:0)
呀。他们的文件很可怕。他们没有很好的例子。您可以尝试使用FileReader
对象和readAsArrayBuffer
方法。类似的东西:
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function(file) {
return function(e) {
var upload;
if (e.eventPhase == 2) {
upload = new AWS.S3.ManagedUpload({
params: {Bucket: 'annuals-original', Key: 'name', Body: e.currentTarget.result}
}).send(function(err, data) {
console.log(err, data);
});
};
})(f);
// Read in the image file
reader.readAsArrayBuffer(f);
您可以将eventHandler附加到输入标记。
<input type="file" id="input" multiple onchange="handleFile(this.files)">
然后将文件传递给处理程序。
inputElement.addEventListener("change", handleFile, false);