Link public for API

Hello, I’m uploading an image using s3.upload and then retrieve it using s3.getSignedUrl, which returns me a link similar to this: https://gateway.storjshare.io/tweets/my_image.png… .
Problem is that when accessing this URL it downloads, I would like to display an image as displayed when accessing the link generated by the panel…

If you want to embed the image in a website, you’ll want to use an <img src="presigned_url">.

Not entirely sure what you mean by panel, can you explain further?

Hello, in case of the panel, I speak directly from the Dashboard, as shown in the print, after clicking on share, the link is generated as https://link.storjshare.io/j
My question is how to have this shareable link without going directly through the Dashboard, direct of API.

To get a link sharing url via the API, you’ll need to use uplink. For example:

uplink share --url sj://tweets/my_image.png

Although for uplink to be able to decrypt the files you’ve uploaded via the s3.upload command you’ll need to use the same encryption passphrase as your S3 compatible credentials when you set up an access grant for uplink.

Alternatively, you could use uplink cp to upload files. Are you using NodeJS or doing something in the browser with javascript?

1 Like

I’m using NodeJS, aws-sdk/clients/s3 in the case

You could shell out to uplink and get the url that way

const { spawn } = require("child_process");
const { join } = require("path");

try {
  const cmd = `${join("/usr/local/bin", "uplink")}`;
  let sharePath = "sj://demo-bucket/storj-tree.png";

  const uplinkProcess = spawn(cmd, ["share", sharePath, "--url"]);

  uplinkProcess.stdout.on("data", (data) => {
    // console.log("output", `${data}`);
    data = data.toString();

    // parse the URL from uplink output.
    // Example output:
    // URL       : https://link.storjshare.io/s/....
    const regex = /URL\s+:\s+(.*)/g;
    const match = regex.exec(data);
    if (match) {
      // match[1] is the first captured group (output captured in parentheses above)
      console.log(`share url: ${match[1]}`);
    }
  });

  uplinkProcess.stderr.on("data", (data) => {
    console.error(`${data}`);
  });
} catch (err) {
  console.error(err);
}

Output

share url: https://link.storjshare.io/s/jvyjw5j7j6cd2rjfwifjsc755b4q/demo-bucket/storj-tree.png
2 Likes

Thanks for example.
I just verified that using the link with https://gateway.storjshare.io/… it has an expiration time. Is there any way to use it without expiring?

Ah okay,

I think presigned URLs always have to have an expiry time, so there isn’t a way around that. You should be able to achieve what you want with a public bucket.

Storj doesn’t have the same sort of concept of public buckets that S3 has. You’ll need a link sharing key prefix for your bucket to do so.

To make the bucket public (readable by anyone on the internet) run this command with uplink. Only have to do this once

uplink share --url --readonly --disallow-lists --not-after=none sj://BUCKET

You’ll get a Browser URL, but the URL is not quite right. It will be in the form of https://link.storjshare.io/s/LINKSHARINGKEY/BUCKET/. To make the content embeddable, swap the /s/ for /raw/. Then to access any files in the bucket, prefix it with https://link.storjshare.io/raw/LINKSHARINGKEY/BUCKET/ plus the name of the file.

E.g. https://link.storjshare.io/raw/LINKSHARINGKEY/BUCKET/my_image1.png
https://link.storjshare.io/raw/LINKSHARINGKEY/BUCKET/my_image2.png

That will allow you to access the files publicly without having to generate an uplink share each time and the urls won’t expire as long as the file remains in the bucket.

5 Likes