Reputation: 905
I want to host a PDF generated in an ios app on Parse server and then retrieve a download URL from parse so that I can send the URL to print node to be printed.
Is this possible?
Upvotes: 0
Views: 841
Reputation: 4378
A PFFile
on iOS has a url
parameter that will be the url to reach your file.
Note that if you are doing local testing, with a locally hosted parse-server instance, the url may end up being "localhost:/" which will obviously not be accessible to the rest of the internet.
Here is a link to the iOS SDK's PFFile API reference: http://parseplatform.org/Parse-SDK-iOS-OSX/api/Classes/PFFile.html#/c:objc(cs)PFFile(py)url
Upvotes: 1
Reputation: 2788
In iOS you need to first to create PFFile. Your PFFile should contain the PDF data and the content type of it (it's part of the PFFile constructor). It's important to provide the content type in order to view the PDF directly by clicking on the URL.
After you create the PFFile you must attach it to some PFObject in order to have access to it. So you first save the PFFile, after saving you attach it to PFObject in the following way:
let pdfData = Data()
let f = PFFile(data:pdfData , contentType: "application/pdf")
let o = PFObject(className: "MyCustomClassName")
o.setObject(f, forKey: "file")
o.saveInBackground { (success, error) in
// upon success the object will be available in parse-server.
}
From the code above you can see that first you need to create pdfData (in my code is empty but in your code you will need to pass the content there). Then, you create a PFFile with data and contentType and then you assign it to PFObject and finally you save the object. In this code I assumed that you use Parse iOS SDK and you initialized it ahead. In order to see the URL you can either go to your MongoDB search for "MyCustomClassName" collection and then you will see it there. I personally recommend you to use parse-dashboard which will show you all your parse objects, files and more in a very nice and intuitive UI
Upvotes: 1