In many cases using a string makes the code. As of now, URL objects are often more convenient, but strings can still be used as well. In old times, before URL objects appeared, people used strings for URLs. Where DistributionPublicUrl is the URL that I started with, the page that allows you to download a file. The URL became longer, because each cyrillic letter is represented with two bytes in UTF-8, so there are two. Creating such an object from a ContentVersion gives you several URLs:
If the URL uses the HTTP or HTTPS protocol, the request includes all the relevant cookies, that is, those cookies set for the URLs hostname, secure flag, path, and so on. First, we use fetch to get the ReadableStream data of the image Next, we call the blob method provided by fetch to get the raw image data Third, we use the URL Web API to call the createObjectURL static method to create a URL that represents the images download URL Finally, an anchor element is created to set the new url to the href attribute. UPDATE: Yrc Shk suggests to use the DistributionPublicUrl object. downloads.download () The download () function of the downloads API downloads a file, given its URL and other optional preferences.
Is there a way to programmatically derive the second URL from the first URL? As you can see, the original URL does not contain something like that. With googling I found that there are links like that should do that, but they require a Content Version record Id, which always starts with 068. I would like to have a link to the file itself, without any HTML wrapping it. However, this is a page that displays the file with a download link. I have publicly accessible files in Salesforce (accessible by anyone, even without a Salesforce license), which can be accessed via URLs such as this: