The pass "pass.pkpass" could not be opened
dariye opened this issue · comments
I keep getting this error: The pass "pass.pkpass" could not be opened. Below's my code. I've re-done the cert process like 3 times. Not sure where it's failing because the package seems intact.
def show
pass = Pass.find(params[:id])
pass_path = ENV['passes_folder_path'] + "/passes/#{pass.id}"
pass_json = File.read(pass_path + "/pass.json")
pkpass = Passbook::PKPass.new pass_json
files = []
Dir.foreach(pass_path) do |file|
next if file == '.' or file == '..' or file == '.DS_Store'
files << file
end
pkpass.addFiles files
send_data(pkpass, type: 'application/vnd.apple.pkpass', disposition: 'attachment', filename: 'pass.pkpass', status: 201, location: [:api, pass])
end
You can not send pkpass as is in send_data
You have to call pkpass.file.path
which will return the temporary pkpass file path
Sorry it could be a little bit more documented. Will update doc in order to get that a bit more clear.
Let me know if it solved your issue.
WOW! thanks for the prompt response. That returns nil
for me.
This time it is something different. You are only giving the filename and not the file path.
Dir.foreach(pass_path) do |file|
next if file == '.' or file == '..' or file == '.DS_Store'
files << File.join(pass_path, file)
end
This should solve this other issue.
ah! okay. I'll. Worked like a charm! BTW, I'd love to help with documentation and contributing.
I'm sending pkpass responses like this:
pkpass = Passbook::PKPass.new # ... initialize & add files
send_data(pkpass.stream.string, filename: "pass.pkpass", content_type: "application/vnd.apple.pkpass")