Start a new topic

Issue with Files download URL

 Hey guys, I'm having trouble trying to get a file download URL. I saved the files with the public attribute as true, so there shouldn't be any problem there. I'm trying to get the url using REST as shown in the guides:

http://devcenter.kinvey.com/rest/guides/files#Downloading


unirest.get(host + '/blob/' + appKey + '/id')
     .headers({'Authorization': 'Basic ' +

      new Buffer(username + ':' + password).toString('base64');,

      'X-Kinvey-API-Version': '3'})
     .end(function (response) {
      console.log(response.body);
     });


But I keep getting the same authorization error no matter how I change it:


401 UNAUTHORIZED -- { "error": "InsufficientCredentials", "description": "The credentials used to authenticate this request are not authorized to run this operation. Please retry your request with appropriate credentials", "debug": "" }



 Hi Andres,

As the guide you linked mentions, downloading a file from Kinvey is a two-step process -- you first make a request to Kinvey to fetch the file's metadata, and then inspect the response to find the download URL, since the file itself is hosted on Google Cloud Storage.


Setting a file's _public attribute to true will result in the download URL being unsigned -- that means that the URL you get from Kinvey will not expire, and will be accessible by anyone on the internet. However, in order to fetch the file metadata and generate that URL, you still have to make an authenticated request to Kinvey, and the requesting user must have sufficient access to fetch the file's metadata. By default, files uploaded to Kinvey have ACLs that only allow the creator of the file access to read it. If you wish to allow other users access to this file, you can set its ACL just as you would any other entity (http://devcenter.kinvey.com/guides/security#Entitylevelpermissions).


Hope that helps!

Thanks,
Yesterday I solved the issue I was having. As you say setting the public attribute to true was not enough for anyone to access the file, I also had to add the gr: true (global read) attribute to the file's ACL. This solved the problem.

 

Login or Signup to post a comment