Skip to content

IOS/Swift Retrieve file field after login throws error code: 151 (version: 1.12) #812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
leonardojobim opened this issue Feb 7, 2016 · 6 comments

Comments

@leonardojobim
Copy link

The code below works well if the user had signed up and didn't log out yet.
But if the user logs out and then logs in again, it throws the following error: [Error]: Can't download a file that doesn't exist on the server or locally. (Code: 151, Version: 1.12.0)
Apparently, login function is not retrieving extra file fields properly:

if let user = PFUser.currentUser() {
  if let photo = user["profilePhoto"] as? PFFile {
    photo.getDataInBackgroundWithBlock({ (data: NSData?, error: NSError?) -> Void in
      dispatch_async(dispatch_get_main_queue(), {
        if let data = data {
          self.profileImageView.image = UIImage(data: data)
        }
      })
    })
  }
}
@leonardojobim leonardojobim changed the title IOS/Swift Access file field after login causes error code: 151 (version: 1.12) IOS/Swift Retrieve file field after login causes error code: 151 (version: 1.12) Feb 7, 2016
@leonardojobim leonardojobim changed the title IOS/Swift Retrieve file field after login causes error code: 151 (version: 1.12) IOS/Swift Retrieve file field after login throws error code: 151 (version: 1.12) Feb 7, 2016
@nlutsenko
Copy link
Contributor

Hey @Leo-One, thanks for the report.
Are you seeing this with Parse.com or self-hosted Parse Server?

Is there any chance you can log network response on logout per instructions here - https://github.com/ParsePlatform/Parse-SDK-iOS-OSX/wiki/Network-Debug-Tool

@nlutsenko nlutsenko self-assigned this Feb 7, 2016
@leonardojobim
Copy link
Author

Hi @nlutsenko
I am using self-hosted Parse Server with Heroku and MongoLab add-on.
The same code works well with Parse.com , but I am migrating.

This error does not occur in queries (PFQuery(className: "AnyClass")) or when sign up. Only in login.

I'll try to use the network debug tool.

@nlutsenko
Copy link
Contributor

Thanks. I wonder if there is something missing in Parse-server implementation of login endpoint.
We definitely should be sending full data back, but there might be something missing.

@leonardojobim
Copy link
Author

I configured the network debug.
There is no additional log when I try to retrieve an image, just the error already described above.
But I think the information below could be relevant. In the json returned by login, there is no url field in the image attribute. But in the json returned by query and update (PFUser.currentUser().saveInBackgroundWithBlock), this field exists:

From a simple query (PFQuery): there is url field inside "userProfilePhoto" attribute
Response Body : {"results":[{"objectId":"RrL0joXFT7","userProfilePhoto":{"__type":"File","name":"1bef99e98f1c3c9f6167967234233410_file.bin","url":"http://hdsHErzjFq.herokuapp.com/parse/files/NkPxYYYXVl4mXdIQgEz1lu24EeNTT9jnw7QDjuCU/1bef99e98f1c3c9f6167967234233410_file.bin"},

From an update (PFUser.currentUser().saveInBackgroundWithBlock) just after the sign up: there is url field inside "profilePhoto" attribute
Method : Optional("PUT") Headers : Optional(["X-Parse-Installation-Id": "861a8001-d38a-42cd-acf6-8f4077cc6c11", "X-Parse-Session-Token": "r:389e069de3909091938953462947399f", "Content-Type": "application/json; charset=utf-8"]) Request Body : Optional("{\"profilePhoto\":{\"__type\":\"File\",\"url\":\"http:\\/\\/hdsHErzjFq.herokuapp.com\\/parse\\/files\\/NkPxYYYXVl4mXdIQgEz1lu24EeNTT9jnw7QDjuCU\\/76d023fa994633d984a47378d7771cfa_file.bin\",\"name\":\"76d023fa994633d984a47378d7771cfa_file.bin\"}}"))

From Login: no url field inside "profilePhoto" attribute
Response Body : {"objectId":"j1t330lPEd","email":"[email protected]","username":"[email protected]","gender":"male","name":"Ze","installationId":"fd5e35b9-2968-430b-9081-92f27e1739c2","updatedAt":"2016-02-07T01:50:05.910Z","createdAt":"2016-02-07T01:49:30.259Z","profilePhoto":{"__type":"File","name":"1bef99e98f1c3c9f6167967234233410_file.bin"},

@leonardojobim
Copy link
Author

It looks that is lacking url property for file fields in the json response of the login function of the iOS/Swift SDK.

@nlutsenko
Copy link
Contributor

Yup, looks like a server bug.
Could you please open an issue on the server repo, since this issue will happen for all the clients.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants