I am concerned with the feasibility of this: On a pre-configured machine I will have a Web-Application pre-installed, next to an Apache-Suite. So client and server are the same!
In this Web-Application Users can drag and drop PDF-Files to an USB-Icon.
Then the Web-App should write the dropped PDF to an attached USB-Stick.
I have never done something like this (writing to USB), so I am fairly insecure. And I am well aware of the browser-restrictions concerning JavaScript and Filesystem-Access, but...
after researching a bit I found out, that there might be some possible and
relevant (I'm a Web-Platform-Guy) solutions to this:
- Make a "Chrome App" with USB-Permission (does this really work?)
- Use PHP to find the USB and then write to it (how would that work under Windows?)
- Use some Flash as middle man (not preferred)
Now I'd like to know:
- Has anyone some good experience with before mentioned possibilities?
- Has anybody ever done something similar? Did it work? Which path did you choose?
- How would I know which drive the USB is mounted, and how would I get sure?
- What other possible solutions to this problem are there?
I am concerned with the feasibility of this: On a pre-configured machine I will have a Web-Application pre-installed, next to an Apache-Suite. So client and server are the same!
In this Web-Application Users can drag and drop PDF-Files to an USB-Icon.
Then the Web-App should write the dropped PDF to an attached USB-Stick.
I have never done something like this (writing to USB), so I am fairly insecure. And I am well aware of the browser-restrictions concerning JavaScript and Filesystem-Access, but...
after researching a bit I found out, that there might be some possible and
relevant (I'm a Web-Platform-Guy) solutions to this:
- Make a "Chrome App" with USB-Permission (does this really work?)
- Use PHP to find the USB and then write to it (how would that work under Windows?)
- Use some Flash as middle man (not preferred)
Now I'd like to know:
- Has anyone some good experience with before mentioned possibilities?
- Has anybody ever done something similar? Did it work? Which path did you choose?
- How would I know which drive the USB is mounted, and how would I get sure?
- What other possible solutions to this problem are there?
- Should the file be saved on the user's USB or a USB where the server is running? – Tim van Osch Commented Aug 4, 2016 at 23:09
- The server would run on the machine. The files would be written to changing/different USB sticks. Every user gets an USB stick as giveaway. – Sebastian G. Marinescu Commented Aug 5, 2016 at 14:53
- What technology is running on the server? Given that you are running a server on the same machine that the USB stick is going to plugged into, your server code could do the filesystem access easily. Without knowing the technology of the back-end, you aren't likely to get any suggested code though. Keep in mind that security is a big concern with this kind of app. Since people can plug a USB stick of their own into this machine that could be a problem unless you lock down the permissions on the machine. – mcgraphix Commented Aug 5, 2016 at 18:38
- @mcgraphix: Let's say that the USB-security-issue is not an issue here. The USB sticks would be provided by trusted staff. As per server-technology I would like to either use PHP or JavaScript (Node) – so one of the mon web-techs for backends. – Sebastian G. Marinescu Commented Aug 6, 2016 at 16:08
- You could acplish this with any server technology. If going with Javascript, you could use ExpressJS for your web app framework (expressjs.) and NodeJS has a built-in module for writing files (nodejs/api/fs.html). But if you are hoping that someone is going to provide you the exact code to acplish your whole project, you will likely find that nobody is going to do that. Try to solve your problem with the suggestions here and then post specific questions based on any roadblocks or trouble you run into. – mcgraphix Commented Aug 8, 2016 at 14:12
3 Answers
Reset to default 5 +100You have a website ('client-side' user interface) and a back-end server ('server-side') running on the same machine. This gives you 2 options:
- Client-side: Download a file through the browser via HTTP GET and let the user choose where they save it.
- Server-side: Build your USB interactions into the back-end (Node.js) code, as @mcgraphix suggests.
Interacting with the USB on the server-side provides the most flexibility. Furthermore, there are a number of libraries that you can leverage. Head to npmjs and consider, among others, the following Node.js server-side packages:
- usb-detection
- usb
With the server-side approach, initiate a Webservice request when the user pletes the drag & drop action on the client, and implement the USB interaction within the server (Express.js or similar) method which services the request.
If the letter of the stick is known then writing a file from PHP will be simple
file_put_contents( 'E:\\folder\\file.pdf', $data );
Update
You can read a list of drives into a dropdown and allow a user to select a default drive to write to
https://stackoverflow./a/8210132/696535
Your question is more an architecture question than a code specific question.
Your web app (if you insist on a web app) should have two major ponents, a server side ponent that can be given arbitrary mands, and a client side ponent (javascript using XMLHttpRequest) that can make requests to the server side ponent to execute said arbitrary mands.
So your server side ponent, the ponent that serves your web page should have some server side code that can write your pdf to the file system, it should probably generate the pdf file as well rather than doing that on the web browser.
Which technology you use is up to you, whether that's PHP, .Net, Node.js etc...
The general gist is you want a server side framework that deals with HTTP requests, in your case probably a post request from the client side containing the encoded pdf, and responds accordingly. Bind a particular http route to trigger your save logic.
Your http post request to the server will contain your payload which is the pdf file to a particular path, e.g. http://localhost/savepdf that whichever technology stack http listens to (you'll need to configure that)
Your server side ponent should read the ining data, decode it as appropriate then make a file system request to write the received payload to disk.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744312329a4568010.html
评论列表(0条)