简体   繁体   中英

Deleting a PFFile from Parse via iOS App

I'm trying to allow users to delete a profile image they previously uploaded. I understand that Parse's SDK does not permit deletion of PFFiles, so I must use the REST API correct? I think perhaps my URL is invalid. Am I supposed to use the name of the file as seen in Parse? In my case, profile images are uploaded as "profilePic-(user's objectId).jpg"

Here is my code:

let request = NSMutableURLRequest(URL: NSURL(string: "https://api.parse.com/1/files/profilePic-\(currentuser.objectId).jpg")!)
            request.HTTPMethod = "DELETE"
            request.setValue(appId, forHTTPHeaderField: "X-Parse-Application-Id")
            request.setValue(clientKey, forHTTPHeaderField: "X-Parse-Master-Key")
            NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
                println(response)
            }).resume()

Try something like this:

let request = NSMutableURLRequest(URL: NSURL(string: "https://api.parse.com/1/files/profilePic-\(currentuser.objectId).jpg")!)

request.HTTPMethod = "DELETE"
request.setValue(appId, forHTTPHeaderField: "X-Parse-Application-Id")
request.setValue(clientKey, forHTTPHeaderField: "X-Parse-Master-Key")

let task = NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
    print("Response: \(response)")
})
task!.resume()

More information about the command (including security concerns) can be found in Parse's official documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM