coiso
coiso

Reputation: 7479

How to upload files from a chrome extension?

The difficulty comes from the fact that chrome extensions can only make external http requests through the background.js file which is separate from the extension and all communication between the two are serialized, which removes files.

I've found some solutions from 1++ years ago, but all seem to be very hacky and not working anymore anyway (as tends to happen to hacky solutions).

So I am left wondering if it is possible at all to upload files from a chrome extension that opens on any website.

Upvotes: 0

Views: 1861

Answers (1)

user650881
user650881

Reputation: 2505

If memory serves, I am fairly sure I am making external web requests from a content script in a Chrome extension.

However, if we just consider how to get a file into the background thread, the following options jump to mind, depending on your needs.

  1. chrome.storage can be used to access local storage
  2. chrome.fileSystem can be used to access the host file system
  3. File content could be suitably encoded (say base64) and sent across with chrome.runtime.sendMessage in the JSON message. (I am not sure if there is a message size constraint. I suppose it could be sent in pieces if there were.)

Upvotes: 3

Related Questions