Start a new topic
Answered

Download file: Redentials not authorized, error 401

Hey,


I'm new to the Kinvey SDK. I have uploaded an image to the files collection with one user, and now i'm trying to download it with another user. 


I've used "KCSFileStore.uploadData" to upload the image and saved the fileId when the uploade completes.


When i try to download the file using KCSFileStore.downloadFile(idOrIds, ... ) i get the error: 

Domain=KCSResourceErrorDomain Code=401 "Error downloading file"

"The credentials used to authenticate this request are not authorized to run this operation. Please retry your request with appropriate credentials"


I use  createAutogeneratedUser to get a user, like this:

if KCSUser.activeUser() == nil {

            KCSUser.createAutogeneratedUser(

                nil,

                completion: { (user: KCSUser!, errorOrNil: NSError!, result: KCSUserActionResult) -> Void in

                    print("Got new User ID: \(user.userId)")

                }

            )

        }


I'm uploading and downloading form two different iOS apps running on the same app key and secret. 

Should I generate a user with specific file read options? Could you guide me to some documentation regarding this?


Best Answer

Hi,


You are getting this error because second user does not have permission to access that file.


There are two solutions around this:

  1. If you make the file publicly readable, all authenticated users will be able to access that particular file.
  2. You can make the file accessible by adding read/write permissions for few users in ACL.


Documentation about ACL structure is available here: http://devcenter.kinvey.com/rest/guides/security#entityanduserpermissions


Let me know if you have any questions about this.



Regards,

Wani

Kinvey Support


Answer

Hi,


You are getting this error because second user does not have permission to access that file.


There are two solutions around this:

  1. If you make the file publicly readable, all authenticated users will be able to access that particular file.
  2. You can make the file accessible by adding read/write permissions for few users in ACL.


Documentation about ACL structure is available here: http://devcenter.kinvey.com/rest/guides/security#entityanduserpermissions


Let me know if you have any questions about this.



Regards,

Wani

Kinvey Support

Awesome, that did the trick (along with turning App Transport Security Settings to NSAllowsArbitraryLoads). 

Thank you :)

Login or Signup to post a comment