rxdb: Unable to store blob type attachments in Electron
Case
bug
Issue
I’ve got an error when trying to store an attachment in electron renderer process, with pouchdb adapter.
file: Pick<File, 'name' | 'type'> & { blob: Blob }
await putAttachment(
{
id: file.name,
data: file.blob,
type: file.type,
},
true
);
Throws:
Uncaught (in promise) TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string
or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Blob
Versions
"pouchdb-adapter-leveldb": "^7.2.2",
"rxdb": "^9.12.1",
"electron": "^11.1.1",
Info
- Environment: electron
- Adapter: pouchdb
- Stack: Typescript,React
Code
After I see the source code, problem in this method, Buffer.from can’t accept a Blob parameter.
createBlobBuffer: function createBlobBuffer(data, type) {
var blobBuffer;
if (_util__WEBPACK_IMPORTED_MODULE_3__.isElectronRenderer) {
// if we are inside of electron-renderer, always use the node-buffer
return Buffer.from(data, {
type: type
});
}
/* ... */
And it is impossible to encrypt the blob type attachments, JSON.stringify also can’t accept a Blob parameter.
var _encryptValue = function _encryptValue(value) {
return encrypt(JSON.stringify(value), this.password);
};
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 35 (23 by maintainers)
Commits related to this issue
- Merge pull request #3115 from kuka/tests/electron-test-fix fixes electron spectron test spec, #3022; — committed to pubkey/rxdb by pubkey 3 years ago
😃 https://github.com/pubkey/rxdb/issues/3022#issuecomment-832695350 Thank you for your time 😃
Ok I’ll get on 3 and 4 until you guys figure out the CI issue.
Updated the PR with the Electron error reproduction and some improvements for the example https://github.com/pubkey/rxdb/pull/3098.
I am not sure what is happening here. Everyone has the same problem but noone wants to even update the electron example.
@kuka we also have tests that run inside of electron https://github.com/pubkey/rxdb/tree/master/examples/electron/test But they are disabled in the CI atm because we first have to update electron otherwise it randomly fails.
Added this https://github.com/pubkey/rxdb/pull/3098 but no issue in the test env. Maybe there is something bigger at play or my test is totally off. @Wuchv Would be nice to have you take a look at it.