ファイルをフロントエンドからs3バケットに送信しています。これは、私が読んだものより効率的です。ユニークなaws S3ファイル名の設定方法は?
しかし、私のスキーマ/コレクションのいくつかのために、私は、ファイル/写真が関連付けられているため、IDがありません - 彼らは、アップロードと同じ時間に作成されているように:
$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ファイル名に割り当てることができます。また、蒸留所オブジェクト上にその参照を保持することもできます。しかし、これはハッキリと思われる。
例の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