Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
How to upload files into s3fs and obtain a public url?

I am trying to upload files into amazon s3 using nodejs. I was able to upload ,and create a bucket. However, the return value from the upload does not contain the url that link to that file. Does anyone know how obtain the url ? and how to make the file public so I can access it because I am trying to upload images into my website

var multer = require('multer');
var AWS= require('aws-sdk');

var fs = require('fs');

var S3FS = require('s3fs');

var s3fsImpl = new S3FS('bucketName',{
    accessKeyId:'************',
    secretAccessKey:'***************'
});

s3fsImpl.create();

var multiparty = require('connect-multiparty'),
    multipartyMiddleware = multiparty();

router.use(multipartyMiddleware);


router.post('/upload',function(req,res){

    console.log(JSON.stringify(req.files));
    var file = req.files;
    var stream = fs.createReadStream(file.fileUpload.path);
   return s3fsImpl.writeFile(file.fileUpload.originalFilename, stream, 'public-read').then(function(data){
        fs.unlink(file.fileUpload.path, function(err){
            console.error(err);
        })
    });
   res.send('Sucessfully uploaded to Amazon S3 server');
});
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If you are using JavaScript/Node, you should use the official AWS SDK rather than S3FS.

For example: putObject() function

When using that function, there is an ACL parameter that specifies whether the object should be public:

ACL: 'private | public-read | public-read-write | authenticated-read | aws-exec-read | bucket-owner-read | bucket-owner-full-control',

Alternatively, a Bucket Policy can be used to grant access to whole buckets or sub-directories.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda