PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → [WB] Loading external files - Part 2
[WB] Loading external files - Part 2
Débuté par Gianni Spano, 16 oct. 2017 13:58 - 13 réponses
Posté le 16 octobre 2017 - 13:58
Hello to all

I'm developing a webdev project where i need to load some files from the user pc and save them in a blog field in a database.

As suggested by Mike Allison, i found in the button list, the UPLOAD button that enable me to open a dialog and select a file.
My needed:
After the file selection, i need to know the full pathname of the selected file and, unfortunately, the filename doesn't contains the full path (i imagine for security reasons).
I will explain why i need the full pathname:
The user will select one or multiple files at a time and i will store their pathname in a grid, then when it push the SAVE button (to save all the info about the record) it will read the grid items and extract the pathname to "re-read" the file contents and store it in the longblob field as a binary format.

Is there someone that can suggest me how to proceed??

Thanks in advance
Gianni
Posté le 16 octobre 2017 - 15:27
Hi Gianni,

it looks like you are misunderstanding how upload works and why.

When you upload a file, you send/copy it physically from the browser to the server. For security reasons, the server NEVER has access to the browser side hard drive.

So storing the full BROWSER path in a table then later GETTING/READING it from the server is completely impossible.

What you can do is use the new html 5 upload control where you can store the file information in a looper after selection/drag and drop, on the BROWSER SIDE, then when clicking on the "upload" button, all files are uploaded on the server.

But again, the server doesn't need the full path from the browser side, as it's a place it can NOT access.

Best regards
Posté le 16 octobre 2017 - 17:50
Hi Fabrice

Yes, i already know about the limitation on server side.
In fact i don't want to upload and store the local pathname of a file directly to the server, but i would store it in a table in the browser and further the full path will be read to retrieve the file contents and then store it in a longblob field on a database.
My operation is NOT to load the file server side, but only locally.

I hope this will be possible, otherwise i will try a workaround..if exist!!

Thanks again
Gianni
Posté le 16 octobre 2017 - 18:24
Just check the content of the upload control, as far as i remember you will find the full name of the file in the PC and the name of the temp file created in the server.

Be carefull with the upload control webdev creates one temp file for each atempt to upload of a file and in some situations don't delete it, after a while it will reuse the same temp file name and if the file you are uploanding is smaller than the one with the same temp name it will merge the content of both files.

The temporary files are created in the webdev directory in the tmpupload
Posté le 17 octobre 2017 - 11:24
Hi Paulo

Thanks for the suggestions.

Gianni
Posté le 17 octobre 2017 - 13:48
Hi Gianni,

I do not really understand what you are trying to do, and you seem to think that it's possible to access the local drive from a browser the same way than from a windev application.

Well it's NOT, as the browser is supposed to be isolated from the local machine for security reasons.

Now directly in JS and html 5, there is now an api available, if that is really what you need to do:
https://scotch.io/tutorials/use-the-html5-file-api-to-work-with-files-locally-in-the-browser

But I'm not sure you'll be able to do everything you need

Best regards
Posté le 17 octobre 2017 - 15:20
Hi Fabrice

It's a bit hard to me to explain better my needed in english :) and i admit my poor knowledge of web programming.

But i will try to explain the steps i would like to reproduce:

First, i'm developing a web application for our Neurology doctors and they told me that they need to load on their database a series of documents (radiographies (images), pdf, docs) and other useful files the patient give them .
They load these files (normally) in their pc and they want to "load" these files in a database.
To do that, i thought to put a table with some columns and in one of them i store the full pathname of the local file they want store in the db, then once he terminates the input of the informations, do a save of the records.
Each document (attachments) are saved in the db reading its pathname from table using "hlinkmemo" etc etc to store the file contents in a longblob field in the db.
That's all!!

Thanks again.
Gianni

P.S. the application must run in an Intranet, so the reason because i'm using Webdev.
Posté le 19 octobre 2017 - 10:57
Hi Gianni,

Maybe take a look at the documentation or an example of the upload stuff of webdev. Intranet or internet makes no difference.

To me this is just standard upload control stuff. You donot need the client path name for sure !

Regards
Allard
Posté le 19 octobre 2017 - 11:12
Hi Gianni,

If you want to upload the file from the workstation (pdf / doc etc), why not -

1. use the upload file procedure to put the file into a folder on the server
2. perform procedure to add it into the database as blog
3. delete file from folder

This would -
make it available to everybody as required.
Keep the integrity of the information because the file is deleted from the folder.


Hope this helps,

Mike
Posté le 19 octobre 2017 - 12:27
If your application runs in an intranet, why you dont use windev instead webdev?
Posté le 20 octobre 2017 - 13:54
Hi Markus

Yes. It could be a possibility, but we are working on an Intranet and i should install the application in each computer in the Hospital.. Not a good solution!!
We have an Intranet site where i publish a link with the connection to the server where the application runs. It is more easy and it runs.

In the meantime, i found a solution to solve my needed: when the user access to the site the first time, i create a temp folder with his name, like "\Temp_Admin" and after few tests it is totally transparent to the users and it is running fine. Then i store the pathname in a global variable like "gsTempPath" and it is available from any page loaded.

Thanks.

Gianni
Posté le 20 octobre 2017 - 16:18
Gianni

Try this:

Info(fWebDir())
Info(fDataDir )

to see where files uploaded then use HLinkmemo to start storing files.

I used to do this:

// For each file sent
FOR i = 1 _TO_ UPL_Upload..Occurrence
// Copies the file into the directory of data
UploadCopyFile(UPL_Upload, fDataDir + ["\"] + "Upload", "", i)
END

ie where someone else is doing upload and won't get crossed.

ps. watch out file permssion for upload in file server.

HTH

King
Posté le 21 octobre 2017 - 18:05
Hi King

Thanks.

Gianni
Posté le 22 octobre 2017 - 13:49
Hi again

>>Yes. It could be a possibility, but we are working on an Intranet and i should install the application in each computer in the Hospital.. Not a good solution!!

No you don't

You install it on a server, in a shared directory, and you just setup a LINK on each computer, ONCE.

Then when you update the exe, everybody just starts the new exe, without any change on any machine.

Best regards