简体   繁体   English

使用流星应用程序上的用户ID重命名dropzone.js上的文件

[英]Rename file on dropzone.js with user ID on meteor app

I have a meteor application with the plugin dropzone.js . 我有一个带dropdrop.js插件的流星应用程序。 I want to save the images from the dropzone with the ID of the current user and the file name. 我想使用当前用户的ID和文件名保存来自dropzone的图像。 But I don't know how to add the user ID in front of the file name. 但是我不知道如何在文件名前面添加用户ID。 I can rename the file with 我可以使用

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

My server file is : 我的服务器文件是:

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;
    }
  });
});

But, if I try to get the user ID with Meteor.userId() or this.userId, this doesn't work because I'm in a server side file. 但是,如果我尝试使用Meteor.userId()或this.userId获取用户ID,则此操作不起作用,因为我位于服务器端文件中。 So, do you know how I could pass the user ID on a server side file ? 那么,您知道我如何在服务器端文件中传递用户ID吗?

Import the meteor object into the file where you want the userId and then just use Meteor.userId() . 将流星对象导入到需要userId的文件中,然后使用Meteor.userId() Never pass the userId from the client. 切勿从客户端传递userId。

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;
    }
  });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM