2

I need to get images from Minio bucket, but I cannot display that image. I found out that problem was in link. I cannot open it even with browser. So, here is the problem:

GET https://127.0.0.1:9000/myphotos/Jungles.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=7PAB237ARMGX7RTYHUSL%2F20221202%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20221202T133028Z&X-Amz-Expires=604800&X-Amz-Security-Token=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3NLZXkiOiI3UEFCMjM3QVJNR1g3UlRZSFVTTCIsImV4cCI6MTY3MDAyNzIyNiwicGFyZW50IjoiS2VtYWxBdGRheWV3In0.okb2wO_iLhOlwWeNbixec4R5MRgGw2_KCY_SB9NfuseUI3g9gzTccycbaA6UnZiuuLzbpxPM5tR_hnxa_Y8zWQ&X-Amz-SignedHeaders=host&versionId=null&X-Amz-Signature=281fab24bbe3d651f89c160f5a613512f5e4503f40300ef0008ac94bd9c8f90b net::ERR_CONNECTION_REFUSED

My code that has been used to upload that file:

package main

import (
    "context"
    "log"

    "github.com/minio/minio-go/v7"
    "github.com/minio/minio-go/v7/pkg/credentials"
)

func main() {
    ctx := context.Background()
    endpoint := "play.minio.io"
    accessKeyId := "KemalAtdayew"
    secretAccessKey := "***********"
    useSSL := true

    // init minio client object
    minioClient, err := minio.New(endpoint, &minio.Options{
        Creds:  credentials.NewStaticV4(accessKeyId, secretAccessKey, ""),
        Secure: useSSL,
    })
    if err != nil {
        log.Fatalln(err)
    }

    // make a new bucket called myphoto
    bucketName := "photobucket"
    location := "us-east-1"

    err = minioClient.MakeBucket(ctx, bucketName, minio.MakeBucketOptions{Region: location})
    if err != nil {
        // check to see if we already own this bucket
        exists, errBucketExists := minioClient.BucketExists(ctx, bucketName)
        if errBucketExists == nil && exists {
            log.Printf("We already own %s\n", bucketName)
        } else {
            log.Fatalln(err)
        }
    } else {
        log.Printf("Successfully created %s\n", bucketName)
    }

    // upload you photos
    objectName := "Jungles.jpeg"
    filePath := "/minio-1/Jungles.jpeg"
    contentType := "image/jpeg"

    // upload the zip file FPutObject
    info, err := minioClient.FPutObject(ctx, bucketName, objectName, filePath, minio.PutObjectOptions{ContentType: contentType})
    if err != nil {
        log.Fatalln(err)
    }

    log.Printf("Successfully uploaded %s of size %d\n", objectName, info.Size)
}

I also gave permission and made it public. Still nothing.

<!DOCTYPE html>
<html>
    <head>
        <title> Minio </title>
        <meta charset="utf-8">
    </head>
    <body>
        <div>
            <img src="https://127.0.0.1:9000/myphotos/Jungles.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=7PAB237ARMGX7RTYHUSL%2F20221202%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20221202T124101Z&X-Amz-Expires=604800&X-Amz-Security-Token=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3NLZXkiOiI3UEFCMjM3QVJNR1g3UlRZSFVTTCIsImV4cCI6MTY3MDAyNzIyNiwicGFyZW50IjoiS2VtYWxBdGRheWV3In0.okb2wO_iLhOlwWeNbixec4R5MRgGw2_KCY_SB9NfuseUI3g9gzTccycbaA6UnZiuuLzbpxPM5tR_hnxa_Y8zWQ&X-Amz-SignedHeaders=host&versionId=null&X-Amz-Signature=5027bd8021a58548ce6be5dead3b622afd951f157a289320ef7dab7701baa7d2" alt="Photo from Minio">
        </div>
    </body>
</html>
  • Tried to change html code. Then, found out that it's not html problem.
  • Tried to share in any other possible way except than, "bucket->click on photo -> click on share"
  • Link is invalid, but there is no other proper way to get link to that image in bucket.
Hojamuhammet
  • 33
  • 1
  • 8

5 Answers5

2

The path to your local image seems to be strange. Verify if you can open your image manually, and remove all the parameters after the image extension, it should be Forest.jpg

Dorian
  • 61
  • 2
  • Photo is not damaged. I can open it on bucket. But, when I put in browser, it doesn't work. I tried to remove all parameters after image extension. Yet, nothing has helped. I'm keep getting the same error. But, still thanks for your answer. – Hojamuhammet Dec 04 '22 at 06:47
  • Did you try to verify if you can still open it ? it seems that you downloaded it. If so, try to rename it to "Forest.jpg" when you put it in your "myphotos" folder. In the second hand you try to acces it with https, but it's your localhost, use http instead. Also make sure you have the rights to read it from the outside by opening it with your browser at the url: http://127.0.0.1:9000/myphotos/Forest.jpg – Dorian Dec 04 '22 at 06:56
  • Yes, I have tried. Everything is right, code is also right. If this might be essential, I can edit and post my code. I also gave permission and made it public. Tried without https but, with http. But, still nothing. – Hojamuhammet Dec 04 '22 at 07:00
  • Did you try without the https too ? If it still not working, so I would like to see your code to test it please – Dorian Dec 04 '22 at 07:05
  • Problem was on host. But, then I tried to do everything in localhost. Making request without https has helped. Thanks! – Hojamuhammet Dec 04 '22 at 10:08
1

The path to your local image seems to be strange. Verify if you can open your image manually, and remove all the parameters after the image extension, it should be Forest.jpg

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 07 '22 at 01:27
1

If you have Minio running in a container, it is always a mess with 127.0.0.1 or localhost.

Try to generate the link with the minioclient.

mc alias set myminio http://localhost:9000 user password

mc share download myminio/mybucket/object.txt

it will return something like this:

mc share download --recursive minio/testbucket
URL: http://localhost:9000/testbucket/KUBERNETES_AN_ENTERPRISE_GUIDE.pdf
Expire: 7 days 0 hours 0 minutes 0 seconds
Share: http://localhost:9000/testbucket/KUBERNETES_AN_ENTERPRISE_GUIDE.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20221207%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20221207T130336Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=8668da57727f04e7c7e8b15f5d8852fa3801e323cfbc6198384737b77f54cb0b

That link you can open in your Browser. Note --recursive generate links for all the uploaded files in the bucket. To get one specific use:

mc share download myminio/testbucket/object.txt.

In production mode as you will use full qualified domain names and not 127.0.0.1 or localhost.

Take a look here about the mc command for generating the link. https://min.io/docs/minio/linux/reference/minio-mc/mc-share-download.html

If you have a backend and according to your programming language you can also generate links through the api.

Here you find a example for javascript: https://min.io/docs/minio/linux/developers/javascript/API.html#presignedUrl

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

First , you need to understand the concept of private vs public buckets.

With Public buckets as long as you know Minio's Endpoint , the bucket name and the object name, you will be able to access the object as long as it exists, no authentication whatsoever is needed (i.e. http://192.168.1.101:9000/mybucket/myimage.jpg)

With Private buckets, you'd need to create a pre-signed URL using their SDK and define the link expiration time and Minio credentials, this will result in a very lengthy address and will allow you to access the image temporarily until the link expires

(i.e http://192.168.1.161:9000/mybucket/myimage.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=abc%2F20230620%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230620T032119Z&X-Amz-Expires=1200&X-Amz-SignedHeaders=host&response-content-type=image%2Fjpeg&X-Amz-Signature=19d51dd70663f7bafdd2dc8e786c0326abb8a9f1fd456f658205c874e78cb79a)

For reference, below is how you'd do it using their .NET SDK

 private async static Task createURL(MinioClient minio ,string bucketName , string objectName, int expirationTime)
{

    var reqParams = new Dictionary<string, string>(StringComparer.Ordinal)
        { { "response-content-type", "image/jpeg" } };

    PresignedGetObjectArgs args = new PresignedGetObjectArgs()
        .WithBucket(bucketName)
        .WithObject(objectName)
        .WithHeaders(reqParams)
        .WithExpiry(expirationTime);

    string url = await minio.PresignedGetObjectAsync(args);

    Console.WriteLine(url);
}
rugby2312
  • 1,056
  • 1
  • 10
  • 15
-1

I have this problem and I solved it in the following steps:

  1. Log into MinIO account
  2. Select the bucket you want to access
  3. Click on settings and then click on "Access Policy"
  4. Set your policy to "Public"
  5. Now build your url as following:

https://127.0.0.1:9000/bucket-name/image-name.jpeg

Martin Oputa
  • 349
  • 4
  • 6