Create folder in bucket when uploading file with user id, nodejs, express

0

I hope you can help me, I am creating a video application and I need to create a folder, inside another folder called videos that is in My Bucket, that new folder must have the user id and inside the uploaded videos.

This is my upload.js file ... where should I apply the creation of the new folder in my bucket with the user id?

aws.config.update({
secretAccessKey: 'YOUR_ACCESS_SECRET_KEY',
accessKeyId: 'YOUR_ACCESS_KEY_ID',
region: 'us-east-1'
});

 const s3 = new aws.S3();

  app.use(bodyParser.json());

  const upload = multer({
  storage: multerS3({
    s3: s3,
    acl: 'public-read',
    bucket: 'vsvideoscl',
    dirname: '/videos',
    key: function (req, file, cb) {
        console.log(file);
        cb(null, file.originalname + Date.now()); //use Date.now() for unique file keys
     }
   })
});
    
asked by San Martín Figueroa Pablo 30.10.2018 в 14:24
source

1 answer

0

I do not know about that JavaSctript library to use, but in S3 there are no folders. The archives have a flat name so there is no folder creation operation.

Probably this library that you use call "dirname" to the part of the object name (S3 object key) that is similar to a folder name on a system with folders.

Example: folder / leeme.txt

    
answered by 11.11.2018 в 21:00