Context
I have two steps in my service, uploading and downloading the file. In uploading to the service I get the data through an array of ASCII bytes .
This data is stored in a database. In the download, the data related to the file is searched in the database and written in binary to a temporary file.
From there, I put a watermark, and return the final file to the user. This is a PDF file .
The Problem
The problem is that when the user uploads a file (PDF) that can not be edited. This is not a read-only attribute since the data is being fetched from the database, not the user's computer.
What characterizes the "editability" of the file is a permission assigned within the PDF format when the file is protected .
Objective
What I'm trying to understand is if there is a way to identify if the file:
So that I can handle the application flow and prevent a non-editable file from being stored in the database (and eventually an error is thrown because I can not add the watermark.)
Exemplo do byte[]:
[0] 37
[1] 80
[2] 68
[...] ...
[84006] 10
Remembering that my solution today is to write the file to a temporary location inside the server to do this check. I want to avoid this step and perform any checks directly on the data array that I get from the database.
To rebuild the file from the data stored in the database, I use the following feature:
BinaryWriter Writer = new BinaryWriter(System.IO.File.OpenWrite(fileName));
Writer.Write("variavel_byte[]");