Harry
Harry

Reputation: 505

How to access USB device in chrome?

I need a web application which is used to copy the files from usb drive. I can write a java applet to copy the files from usb drive, but chrome will not support applet any more. Could you please suggest any alternative to this? I need a web application not a chrome app.

Upvotes: 2

Views: 18020

Answers (2)

Colin
Colin

Reputation: 2021

Chrome 61+ has an implementation of the WebUSB API

This would not let you issue a command to the OS/File system to, for example:

copy file://some_file_location/myfile.txt to file://USB_DRIVE/some_folder/myfile.txt

Chrome would need to read the files and write to the device directly. In other words the browser would be copying the files by reading them (see below) and then writing to the USB device. This would probably be quite slow and unfeasible for large files.

Your options to read local files are:

  • To run chrome with the --allow-file-access-from-files flag. This is a security issue/risk, and users would need to visit your site/application with this already on.
  • Use the File and FileReader, or the non-standard FileSystem APIs along with a input type="file" or drag & drop

Neither of these may be applicable to your problem/solution.

Upvotes: 1

KpTheConstructor
KpTheConstructor

Reputation: 3291

I'd recommend using node.js , its cross platform and can access usb ports from web browser..

Usb Library: https://www.npmjs.com/package/usb

Proof : How to send data to USB device in node.js using libusb

Hope this helps

Upvotes: 0

Related Questions