Is there a way to get the share link of an uploaded file through an api call?

Since I’m here, I take the opportunity to ask a question.
Is there a way to get the share link of an uploaded file through an api call? Or do I always have to download the files using project.downloadObject?


You may register a generated access grant on our Auth service with public flag and get the S3 credentials, then construct an URL to our linksharing service, see uplink/access.go at 70a475785b4993bfd8604744ce38bde99acc5c5d · storj/uplink · GitHub and uplink/share.go at 70a475785b4993bfd8604744ce38bde99acc5c5d · storj/uplink · GitHub
The CLI analogue would be

uplink share --public --register sj://my-bucket/my-object.txt

then construct URL with S3 access key and /raw/, i.e.

See implementation storj/cmd_share.go at 209b669e8480739f05170886c11dfc705dd9ef16 · storj/storj · GitHub
However, I do not know is it supported by uplink-android binding, will ask the team.

Please also note, when you use a linksharing service, you limiting the source to a few locations of present of this service (because it has much less servers than if you download directly from nodes across the globe) and this could affect download speed.

I made a very simple example to do this using Go, this uses the uplink library as Alexey linked above: share file programatically using storj linksharing service · GitHub

For Android, looks like you can at least create the restricted access grant with this snippet: GitHub - storj/uplink-android: Storj network Android library then post it to with request body like {"access_grant":"abc123","public":true} to get an access key for Linksharing. The response will look something like {"access_key_id":"abc","secret_key":"abc","endpoint":""}. Then you can build the Linksharing URL using the access_key_id from that response, as Alexey shows above.

1 Like

The C# uplink.NET-library inlcudes such a functionality, see here:

Maybe that helps creating a version with the Java binding.

1 Like

Replace --public with --url and that command will generate and print out the share link.

1 Like

Actually you can replace both. It will:

  • generate an access grant
  • public S3 credentials
  • linkshare URL

However you will need to replace /s/ to /raw/ in the resulted URL to be able to embed it.

1 Like

Thank all of you for all your replies.
Actually the question was not properly formulated because it was extracted from another discussion and I didn’t specify also there that I was looking for something like this for android.

So as cli and c# are not valid options for me right now, I’ll give a try mainly to @sean and @Alexey comments.
Thank you for your support!

1 Like

Excuse me, do you know where can I find more about the api
Is it in the documentation?

There is an OpenAPI specification: gateway-mt/auth-openapi.yaml at 40fb075087ffc07325774ec0913b7e96ef015c0c · storj/gateway-mt · GitHub, but not much beyond that. You can see the handler code for that endpoint here: gateway-mt/resources.go at 40fb075087ffc07325774ec0913b7e96ef015c0c · storj/gateway-mt · GitHub

Go ahead and post any questions on here if you want, and I’ll try my best to answer them.

1 Like

Thank you, I’ll give a look at that, it can be useful.
Do you know if there are limits about the number of requests to that API by any chance? Just to be sure

There are currently no limits set up. We didn’t want to constrain users, but if we detect abuse, w will most likely impose some reasonable limits (like the number of access grants you can register with the same macaroon head).

Also, if you’re looking for more examples of how to interact with Storj-hosted Auth Service, take a look at this gist: How to register an access grant @ Auth Service via HTTP(S) and DRPC(S) · GitHub. They should be fairly easily portable into code (at least HTTP-based ones).

Hello, I have tried in a few ways but I still haven’t managed to succeeded in getting the direct download link. I have some doubts, I’ll write what I have tried first.

The error I get is Unexpected reponse code 405 for or “NetworkUtility.shouldRetryException: Unexpected response code 422 for”.
I guess it’s something related to how i build my url or how I use credentials.

This is what I have tried:

// getting access grant
Access sharedAccess = access.share(
                                new Permission.Builder().allowDownload().build(),
                                new SharePrefix(bucket, mediaName));

                        // Serialize the access grant to, so it can be easily sent to the receiving party.
                        String serializedShare = sharedAccess.serialize();

 RequestQueue volleyQueue = Volley.newRequestQueue(MainActivity.this);

                        JSONObject json = new JSONObject();
                        try {
                        } catch (JSONException e) {
                            throw new RuntimeException(e);

String url = ""+S3_ACCESS_KEY+"/"+bucket+"/"+mediaName;
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, json, {RESPONSE_CALLBACK}, {ERROR_CALLBACK});

I have tried many ways: using or in the url, using /raw/ insted of /s/ and using just “” as url like indicated in your previous comment but no combination worked for me.

The main obstacle is that I am not understanding if post request in order to get the download link in the response is related to S3 and -if yes- how exactly. In this specific topic I feel that your teachings are more helpful than doc for me.
(And also if your and Alexey replies are related too.)
Which are the correct steps to set up I should follow and credentials I should use. :thinking:
(P.S. I have generated S3 credentials from the web interface: access key, secret key and endpoint)

I am sorry if I have many questions which can seem basic, I am very new to Storj and I am trying to figure out how to use it and integrate in my app by myself so it’s a big challenge. :sweat_smile:

HTTP 405 is method not allowed, so you should ensure it is sending a POST request as the method.

HTTP 422 status is “Unprocessable Content”. This gets thrown by authservice if it couldn’t process the JSON body because it doesn’t look like what it expected. Is there a way to print out what the request body is going to send from your code?

should be

String url = ""

after that you will execute a POST request with body json

You should receive in response

Then you will take access_key_id and construct URL for linksharing service as you wrote, i.e.

so, S3_ACCESS_KEY should not be pre-generated.
However, you can use the approach with pre-generated S3 key too, but need to generate them as public, i.e.

To do not have it for each object, you may share the entire bucket or prefix, i.e.

uplink share --public --register --not-after=+1m sj://my-bucket/my-prefix/
=========== ACCESS RESTRICTIONS ==========================================================
Download  : Allowed
Upload    : Disallowed
Lists     : Allowed
Deletes   : Disallowed
NotBefore : No restriction
NotAfter  : 2023-03-02 04:46:29
Paths     : sj://my-bucket/my-prefix/
========== CREDENTIALS ===================================================================
Access Key ID: 1udhy3hrufhrufiodkr
Secret Key   : jzenuhrm4nqkfmkpkhhhspxmhr38j8h8xj73ft6p47ytg27snh7
Endpoint     :
Public Access:  true

And use the generated S3 access key to form an URL.
Or even simpler:

uplink share --url sj://my-bucket/my-prefix/
=========== BROWSER URL ==================================================================
URL       :

and use the generated URL and simple add an object, i.e.

Since you need to embed it, you need to replace /s/ to /raw/:

Thank you, this helped a lot. Now I can make it work in both ways (post request and s3 credentials).
Really grateful to both of you