5

I am using minio to manage the files

const getMinioClient = () => {
  const minioClient = new Minio.Client({
    endPoint: '127.0.0.1',
    port: 9000,
    useSSL: false,
    accessKey: 'minioadmin',
    secretKey: 'minioadmin'

  });
  return minioClient;
};

  uploadFile(bucketName, newFileName, localFileLocation,metadata={}) {
    return new Promise((resolve, reject) => {
      const minioClient = getMinioClient();
      //'application/octet-stream'
      minioClient.fPutObject(bucketName, newFileName, localFileLocation, metadata , (err, etag) => {
        if (err) return reject(err);

        return resolve(etag);
      });
    });
  }

with the following code I can upload the file, after successfully uploading it returns me only with etag, but I want to get the download link, how would I get it directly without searching the filename again.

user824624
  • 7,077
  • 27
  • 106
  • 183

2 Answers2

1

You won't be able to get something like Public URL/Link for accessing images unless you ask for it to manually generate a time limited download URL using something like: https://min.io/docs/minio/linux/reference/minio-mc/mc-share-download.html#generate-a-url-to-download-object-s

One workaround is to let nginx directly access the location you are uploading your files to: https://gist.github.com/harshavardhana/f05b60fe6f96803743f38bea4b565bbf

yashas123
  • 270
  • 5
  • 23
0

After you have successfully written your file with your code above, you can use presignedUrl method to generate the link to your image.

An example for Javascript is here: https://min.io/docs/minio/linux/developers/javascript/API.html#presignedUrl:~:text=//%20presigned%20url%20for%20%27getObject%27%20method.%0A//%20expires%20in%20a%20day.%0AminioClient.presignedUrl(%27GET%27%2C%20%27mybucket%27%2C%20%27hello.txt%27%2C%2024*60*60%2C%20function(err%2C%20presignedUrl)%20%7B%0A%20%20if%20(err)%20return%20console.log(err)%0A%20%20console.log(presignedUrl)%0A%7D)

In any case you have to set an expiration time. Here or you set a very long time, which is suitable to your app or if you have a backend, require the images from Frontend through the backend with the getObject method: getObject(bucketName, objectName, getOpts[, callback]). https://min.io/docs/minio/linux/developers/javascript/API.html#presignedUrl:~:text=getObject(bucketName%2C%20objectName%2C%20getOpts%5B%2C%20callback%5D)

If you have only a few number of static images to show in your app, (which are not uploaded by your app), you can also create the links manually with tme minio client or from the Minio-UI.

Ralle Mc Black
  • 1,065
  • 1
  • 8
  • 16