Reputation: 1070
I need to upload a local file to a remote server from a chrome extension. The extension extends chrome file browser and I'd like to invoke the upload when a user 'opens' a file with my extension. I was hoping to use sockets APIs but just realised (hard way) that the APIs are available in apps only.
Could someone recommend a best practice/approach?
Thanks.
Upvotes: 1
Views: 2154
Reputation: 15841
Use HTTP PUT or POST, the same way you would upload from a web app. From Javascript, you do this with XMLHttpRequest()
, specifying 'PUT' or 'POST' as the first argument to the open()
method (whatever your server requires). MDN has this example (as they note, sendAsBinary()
in the example should be changed to simply send()
).
Upvotes: 1