我尝试使用 edge:slingshot 包在我的 s3 存储桶上上传视频,图像文件可以正常工作,但视频文件出现此错误:“错误:无法将文件上传到云存储 [-0]跟踪:Meteor.makeErrorType /errorClass@ http://localhost:3000/packages/meteor.js?9730f4ff059088b3f7f14c0672d155218a1802d4:525:15 getError@ http://localhost:3000/packages/edgee_slingshot.js?4c5b8e7dc4cae9d464984ead4903ef4beaacshoting.js? 4c5b8e7dc4cae9d464984ead4903ef4beaacshotup.// /<@ http://localhost:3000/packages/edgee_slingshot.js?4c5b8e7dc4cae9d464984ead4903ef4beaac99f5:407:18 "
我的模板事件:
Template.upload_vid.events({
'change input[type="file"]': function ( event, template ) {
var file = event.currentTarget.files[0];
Modules.client.uploadToAmazonS3( { file: file, template: template, type :"video" } );
}});
我的模板:
<template name="upload_vid">
<input type="file" name="file" id="file_vid">
<label for="file_vid">download</label>
</template>
我定义弹弓的函数(仅限服务器端的 slingshot.js):
Slingshot.fileRestrictions( "uploadVidToAmazonS3", {
allowedFileTypes: [ "video/webm", "video/mp4", "video/mov", "video/3gp"],
maxSize: 50 * 1024 * 1024
});
Slingshot.createDirective( "uploadVidToAmazonS3", Slingshot.S3Storage, {
bucket: my_bucket,
acl: "public-read",
authorize: function () {
var user = Meteor.userId();
if(user){
return true;
} else {
return false;
}
},
key: function ( file ) {
var user = Meteor.users.findOne( this.userId );
return user.emails[0].address + "/video_profil/" + file.name;
}
});
和使用 Slingshot 和进行上传的功能(适用于图像):
let template;
let _uploadPicsToAmazon = ...
let _uploadVidToAmazon = ( file, type ) => {
var uploader = new Slingshot.Upload( "uploadVidToAmazonS3" );
uploader.send( file, ( error, url ) => {
if ( error ) {
console.log( error, "warning" );
} else {
console.log("success");
}
});
};
let upload = ( options ) => {
template = options.template;
let file = options.file;
let type = options.type;
if(type == "img"){
_uploadPicsToAmazon( file, type );
}else{
_uploadVidToAmazon( file, type );
}
};
Modules.client.uploadToAmazonS3 = upload;
有人有解决方案吗?事先谢谢你。