-
Notifications
You must be signed in to change notification settings - Fork 9
PDF Attachment tutorial #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
||
<Accordion title="Step 2: Create the `PdfAttachmentQueue` class"> | ||
The `PdfAttachmentQueue` class below updates the existing [PhotoAttachmentQueue](https://github.com/powersync-ja/powersync-js/blob/main/demos/react-native-supabase-todolist/library/powersync/PhotoAttachmentQueue.ts) | ||
found in the demo app. The highlighted lines indicate which lines have been updated. For more information on attachments, see the [attachments package](https://github.com/powersync-ja/powersync-js/tree/main/packages/attachments). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of highlighted lines it very cool!
Co-authored-by: benitav <[email protected]>
Co-authored-by: benitav <[email protected]>
dbFilename: 'sqlite.db' | ||
} | ||
}); | ||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah block comments don't render correctly unfortunately, but that space is very annoying - will definitely fix.
@HeinrichvonStein Overall looks great - made some minor suggestions. One more meta thing is that the "Attachments Storage" heading for this Tutorial group is now no longer that accurate anymore. This PDF tutorial is more about a different file type, rather than the storage part? So maybe rename it to "Attachments / Files" in line with the Use Case Examples title, and rename the AWS S3 tutorial to "AWS S3 Storage" or similar. |
@benitav Thank you for the feedback and quick review. Does "Attachments / Files" not relate to storage though? |
A part of Attachments / Files is storage related (esp the backend side of this), but there is client-side code and stuff as well that's not exactly storage related in my mind. That's more about how to reference these files, as an example. Another way of putting this is a user will more commonly think "I want to sync files", not "I want to store files". |
The `saveAttachment` method in the `PdfAttachmentQueue` class expects a base64 encoded string. We can therefore use | ||
[react-native-fs](https://www.npmjs.com/package/react-native-fs) to read the file and return the base64 encoded string which is passed to `saveAttachment`. | ||
<Note> | ||
If your use-case generates a pdf file, ensure that you return a base64 encoded string. | ||
</Note> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be nice to use expo-file-system/next
at some point - it can read and write files in binary directly, avoiding the need for converting to/from base64.
https://docs.expo.dev/versions/latest/sdk/filesystem-next/#bytes
This change introduces a new pdf attachment tutorial.
The tutorial can be viewed here