Re: Help with file upload please.

Tony Corless via Exist-open <[email protected]> Mon, 2 Dec 2024 17:44:11 +0000
Newsgroups gmane.text.xml.exist
Message-ID <DB9PR06MB740318EBB4B33F8C3310F6E6D1352@DB9PR06MB7403.eurprd06.prod.outlook.com>
Thanks Joe and Jean-Paul
As you’d expect things are now working exactly as I’d hoped.
Tony


From: Joe Wicentowski <[email protected]>
Sent: 02 December 2024 17:16
To: Corless, Tony (Comp Sci & Elec Eng) <[email protected]>
Cc: [email protected]
Subject: Re: [Exist-open] Help with file upload please.

Hi Tony,

Instead of the request:get-parameter function, use request:get-uploaded-file-data. See:

  https://exist-db.org/exist/apps/fundocs/view.html?uri=http://exist-db.org/xquery/request#get-uploaded-file-data.1

Joe

On Mon, Dec 2, 2024 at 4:20 AM Tony Corless via Exist-open <[email protected]<mailto:[email protected]>> 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
[email protected]<mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/exist-open

_______________________________________________
Exist-open mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/exist-open