2017-05-07 73 views
0

与用户ID dropzone.js文件I具有与插件dropzone.js流星应用。我想从悬浮窗将图像保存与当前用户的ID和文件名。但我不知道如何在文件名前添加用户ID。我可以将文件与重命名流星应用

getFileName: function(file, formData) { 
     return 'some text' + file.name; 
    } 

我的服务器文件重命名为:

Meteor.startup(function() { 
    UploadServer.init({ 
    tmpDir: process.env.PWD + '/public/uploads', 
    uploadDir: process.env.PWD + '/public/uploads', 
    checkCreateDirectories: true, 
    uploadUrl: '/upload', 
    // *** For renaming files on server 
    getFileName: function(file, formData) { 
     return file.fileName + file.name; 
    } 
    }); 
}); 

但是,如果我试图让与Meteor.userId()或this.userId用户ID,这不因为我在服务器端文件中工作。 那么,你知道我怎么能传递一个服务器端文件中的用户ID?

回答

0

导入流星对象到您想要的用户id,然后只用Meteor.userId()文件。 决不从客户端传递的用户ID。

import { Meteor } from 'meteor/meteor'; 

Meteor.startup(function() { 
    UploadServer.init({ 
    tmpDir: process.env.PWD + '/public/uploads', 
    uploadDir: process.env.PWD + '/public/uploads', 
    checkCreateDirectories: true, 
    uploadUrl: '/upload', 

    // *** For renaming files on server 
    getFileName: function(file, formData) { 
     return Meteor.userId() + file.fileName; 
    } 
    }); 
}); 
+0

在我的文件在服务器端导入不起作用 – Adrien

+0

如果它不,那么你有其他问题。你使用什么版本的Meteor? –

+0

我使用的版本流星 – Adrien