From: Jean-Paul R. <re...@gm...> - 2024-12-02 10:00:32
|
Dear Tony, It seems you are trying to access the uploaded file (jpg, pdf, etc) via request:get-parameter()....but the file is not a parameter to the request. You need to use request:get-uploaded-file-data() within the context of multipart/form-data. This function takes the name from the file you uploaded, *not from an input*. This is accessed with request:get-uploaded-file-name() See https://exist-db.org/exist/apps/fundocs/view.html?uri=http://exist-db.org/xquery/request&location=java:org.exist.xquery.functions.request.RequestModule JPR On Mon, Dec 2, 2024 at 10:20 AM Tony Corless via Exist-open < exi...@li...> wrote: > Hello all, > > > > I am getting something slightly wrong and I’m not sure what. This is still > new to me, so likely I am making a silly error. > > I want to provide users with a form that allows them to upload PDF files > from their PC to the database. The form will also have information about > the PDF, which is working as expected. > > > > For a test I have two XQueries one to post the data and the other to save > it: > > > > xquery version "3.1"; > > declare option exist:serialize "method=html media-type=text/html > indent=no"; > > <html><body> > > <p>file upload test</p> > > <form method="post" enctype="multipart/form-data" > action="./storeFile.xql"> > > <input type="file" id="myFile" name="posted"/> > > <input type="submit"/> > > </form> > > </body></html> > > > > > > and > > > > xquery version "3.1"; > > declare option exist:serialize "method=html media-type=text/html > indent=no"; > > declare variable $received := request:get-parameter("posted",()); > > let $filePath :="/db/apps/scratch/data/files" > > let $fileName := "test.pdf" > > return > > <html><body>Received {($filePath, $fileName, > xmldb:store-as-binary($filePath, $fileName, $received))}</body></html> > > > > The result is that I get a file test.pdf in the target directory but it > displays only as blank pages. The same file uploaded through the admin > client displays correctly. > > (I get the same result with a side range of PDF files. If I change to > store a JPG then I get a blank image from the XQuery route and the expected > image using the admin client.) > > > > I feel that I am missing something that is obvious and trivial to those > who know what they are doing! > > > > Any input welcome. > > Tony > > > _______________________________________________ > Exist-open mailing list > Exi...@li... > https://lists.sourceforge.net/lists/listinfo/exist-open > |