Attachments Support
See original GitHub issueThis issue is to act as a placeholder for work remaining to fully support Attachments.
The remaining issues are as follows:
- On replication to remote CouchDB where the local doc contains an attachment it should successfully sync the doc and attachment data. If doc contains an attachment sync fails.
- On replication from remote CouchDB were the remote doc contain an attachment it should successfully sync the doc and attachment data. If doc contains an attachment sync fails.
Considerations unique to ReactNative:
(Note: these following information is based on my observations, some accuracy may be missing, please correct where appropriate. I’m still learning how the ReactNative packager works.)
- ReactNative has 2 runtimes V8 in Debug and JSC in Release.
- During Debug (simulator build in Debug) the application is packaged targeting the browser (Chrome V8) and we have access to the window and DOM and other browser native implementations e.g. Blob
- During JSC Release (simulator build in Release) the application is packaged targeting JSC and we do not have access to the window and DOM. JSC isn’t at feature parity with V8. Blob is replaced with node’s Buffer.
- Most polyfills fallback to native browser when available, which causes some interesting results between Debug and Release.
- ReactNative only uses fetch
- PouchDB has many dependencies - adapters, plugins, utils - each of these are packages for node or browser. However, ReactNative packager always chooses the browser version during package resolution (based on my testing)
Research:
- This library currently has a hack during the
postinstal
phase, where thepouchdb-binary-utils/package.json
is patched to force the ReactNative packager to chose the node versions of the library. - If I remove the above hack locally:
- I can successfully get sync to work for all use cases, on iOS simulator in V8 Debug. This is due to the reliance on both this library and all Pouchdb dependencies choosing browser installs, and and native browser lib implementations, all the way down.
- During JSC release mode, on iOS simulator, I receive Blobs from the
pouchdb-adapter-http
, which in turn delegated topouchdb-ajax
. Since ReactNative runtime JSC has no support for FileReader/FileReaderSync we do not have a utility to transform aBlob
toBuffer
orBase64
. more context here- I believe we can get an
ArrayBuffer
in all cases instead of returning aBlob
and be in a better situation. More research needed here. - We also cannot opt for the the node version of
pouchdb-ajax
because it relies onrequest
which will not work in ReactNative without hacks to expose additional core node modules.
- I believe we can get an
Next Steps:
- I’ve been building out test cases for Attachments. All scenarios pass. This is due to our test suite being run in a fully node.js context and doesn’t represent the ReactNative runtime. In the future it would be beneficial to extend coverage to more environment.
- I’ve currently forked both
pouchdb-adapter-http
andpouchdb-ajax
and have created ReactNative versions of these and am experimenting with getting full support for both Debug and Release. For these versions I’m supporting onlyfetch
and always returningArrayBuffer
neverBlob
. This is getting close. However, many tests are not passing locally. - I believe if we can patch the above utilities then we will have full - or very close - support for Attachments in this library, for both the Debug and Release contexts.
- I am worried that this effort could snowball into to essentially forking PouchDB, but right now I’m not seeing the need for this.
- I could use some additional direction in terms of patching
pouchdb-adapter-http
. My current build hasn’t made any changes except to the new pouchdb-ajax delegation library. There is currently no way to provide strategies without having direct access to the PouchDB instance. Long term this will not be maintainable without a strategy pattern in place at plugin registry. Also, there may be much better ways of injecting a different implementation, will need some direction from @nolanlawson e.g.
const db = new PouchDB('local');
db._ajax = fetchCore;
Issue Analytics
- State:
- Created 6 years ago
- Reactions:9
- Comments:47 (1 by maintainers)
Top Results From Across the Web
Add attachments to emails in Mail on Mac - Apple Support
Click the Attachment button in the toolbar, locate a file, select it, then click Choose File. You can also drag files from the...
Read more >Send and receive attachments - Microsoft Support
Training: Attach pictures, files, contacts, emails and other items with your email in Microsoft Outlook. See how in this online video training.
Read more >Attachment - AWS Support
An attachment to a case communication. The attachment consists of the file name and the content of the file.
Read more >Open & download attachments in Gmail - Android
When you get an email with attachments, you can download a copy of the attachment to your ... Ask the Help Community Get...
Read more >Attachments Plus App Integration with Zendesk Support
Integrate the Attachments Plus app into Zendesk Support. Displays all attachments and links of the ticket.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@stockulus I’ve started working on the migration. Hopefully I’ll have this completed this weekend.
Hey, I’ve got it to work with minimum changes to core packages. Read my blogpost: https://dev.to/craftzdog/hacking-pouchdb-to-use-on-react-native-1gjh