1

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.

2
  • Just use PUT or POST, the same way you would upload from a web app. Commented Jun 3, 2015 at 14:46
  • Would you be able to provide an example? I could handle uploads using a 'standard' way - i.e. HTML file input. However, I need to initiate the upload from within a javascript. Commented Jun 3, 2015 at 15:41

1 Answer 1

1

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()).

Sign up to request clarification or add additional context in comments.

3 Comments

The example assumes that files were selected by a user. That is, FileList and File object are created as a result of user interaction. In my case, I get a file name from the file manager. How can I upload it without creating a page with file input?
It shows how you upload a file. I thought you already knew how to get the file itself. Can you clarify your question?
I just realised that I have what I need. The file browser gives me a File object which I should be able to use with PUT/POST as you described.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.