parse-platformdownloadswift2ios9pffile

How to "properly" save PFFile in Swift and retrieve url


I am having a difficult time with Parse.com.

I save a PFFile through my app, using the following code... (truncated to relevant info.)

let alertXMLFile = PFObject(className: "Message")
do {
    alertXMLFile["alertFile"] = try PFFile(name: "alertFile.xml", data: data!)
    } catch {
        print("upload fail")
    }
alertXMLFile.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in   
    }
}

When I go to the web and view the file, I click on it and it downloads instead of showing in the browser. (The download also happens if I copy the link and paste into another browser) I can take that downloaded file, upload it via the web into my class, click on it, and it shows in the browser. My app will also properly recognize the manually uploaded file and execute as expected .

My question is, how to save a PFFile to Parse.com in iOS via Swift 2.1 that will not be a forced downloadable object, but will react as if manually uploaded?

Here is a link to a successfully saved file... http://files.parsetfss.com/277284ac-afb0-445c-b352-863782ca3acd/tfss-0c5b843d-d1cf-4b85-a9f5-aebff98d656c-alertData.xml


Solution

  • This behaviour is usually determined by MIME Content-Disposition property being sent by the server to your browser. This property is set to inline if the image that is intended to be viewed by the user immediately, otherwise it is set to attachment which usually forces your browser to download it. (see Examples in RFC 2183)

    I think this MIME type is set differently when the file is uploaded manually via the dashboard. I have not done this myself but according to the documentation you can create a PFFile and set the content-type using fileWithName:data:contentType: