GLB file type changes when trying to dwonload it from s3 through a signedURL from my s3 bucket

Viewed 21

I am using s3 for storing/accessing my files ".glb" files, when the file gets uploaded it is uploaded as a ".glb" file type, but when I am trying to access it through the signedURL it is coming as a "file" file type

exports.uploadGLB = async (req, res) => {
  const file = req.file;
  //console.log("skslsk", file);
  let { _id } = req.params;
  //console.log("ID", _id);

  const imageName = generateFileName();
  
 const result = await uploadFile(file, imageName, file.mimetype)

  
  await unlinkFile(file.path);
 console.log(">>>>>>>>>>>>>>>",result)

 User.findOneAndUpdate(
  { _id: _id }, 
  { $push: { metaSpaces: result  } },
 function (error, success) {
       if (error) {
           console.log(error);
       } else {
           console.log(success);
       }
   });

  res.status(201).json({
    message: "Uploaded",
  });
};
The above code snippet is to upload and to generate the signedURL from s3-config.js file. The below mentioned code is the controller of that api responsible for uploading the file

exports.uploadFile = async (file, name, mimetype) => {
  //console.log("Uploadingg,,,,,,")
  //console.log("paramsss", fileBuffer, fileName, bucketName)
  const uploadParams = {
    Bucket: bucketName,
    Body: fs.createReadStream(file.path),
    Key: name,
    ContentType: mimetype,
  };
  const signedUrlExpireSeconds = 60 * 5;

  let url = s3Client.getSignedUrl("getObject", {
    Bucket: bucketName,
    Key: name,
    Expires: signedUrlExpireSeconds,
  });

//  console.log("url", url);
  return new Promise( (resolve, reject) => {
    s3Client.upload(uploadParams,(err,data)=>{
     if(data){
      let res = {url:url}
      resolve(Object.assign(res,data))
     }else
     {
      reject(err)
     }
  })
}); 


};

This is the log result after the file is successfully uploaded in the S3, where you can see that it is clearly the mimetype. { fieldname: 'glb', originalname: 'Tiger.glb', encoding: '7bit', mimetype: 'model/gltf-binary', destination: 'files/', filename: '534e864015afbad9724e6686e19c481b', path: 'files\534e864015afbad9724e6686e19c481b', size: 9201964 } f998b0a3efe7b9f0387580c9bc3dea0fc36e754839f029522cc46631c4fedc8f model/gltf-binary

but when I am trying to access the same file using the generated signedURL the type of the file is changing to only "file", it is showing when I am checking its properties. Screenshot of the property of the file, which is showing the file type

but when I am following exact same steps for any image file like png, jpeg, etc it is working fine without any issue, I am able to access the exact file which one is uploaded.

any solution for the above problem will be appreciated, really hoping for a solution. Thank you in advance.

0 Answers
Related