我正在通过前端将我的文件发送到s3存储桶,因为从我读过的内容看,这似乎更有效率。如何设置一个独特的aws S3文件名?
但是,对于我的一些模式/收藏品,我不会有相应的文件/照片相关的标识 - 因为他们正在创建的同时上传:
$scope.add = function(){
if($scope.file.photo){
$scope.distiller.photo = 'http://s3.amazonaws.com/whiskey-upload/distillers/'
+ ' needs to be assigned to guid or collection id'
Distillery.create($scope.distiller).then(function(res){
console.log(res);
$scope.distillers.push(res.data.distiller);
var files = $scope.file;
var filename = files.photo.$ngfName;
var type = files.type;
var folder = 'distillers/';
var query = {
files: files,
folder: folder,
filename: res.data.distiller._id,
type: type
};
Uploads.awsUpload(query).then(function(){
$scope.distiller = {};
$scope.file = {};
});
});
}
else{
Distillery.create($scope.distiller).then(function(res){
toastr.success('distillery created without photo');
$scope.distiller = {};
});
}
};
的上面的代码将无法工作,除非我在创建了酿酒厂对象并将文件上传到s3之后发送了有关aws.Upload承诺的更新。
这似乎没有效率。
我可以创建一个GUID并将其指定给s3文件名,并且还可以在该DRS对象上保留一个引用。不过,这看起来很诡异。
例子的Guid创造者:
function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
什么是实现我想要的最彻底的方法?
你可能要考虑使用像fineuploader – dkarchmer