我正在通過前端將我的文件發送到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