Skip to content
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

fix: resize large images attachments on upload #1824

Merged
merged 5 commits into from
Feb 28, 2023

Conversation

zaidhaan
Copy link
Contributor

@zaidhaan zaidhaan commented Feb 25, 2023

Mastodon's API has a 4096x4096px file size limit on image attachments, its web client however simply resizes larger images on the client-side to an acceptable size for the API request.

This PR brings this functionality to elk. The approach is based on theirs, though re-written by myself in a much more stripped down way.

To test, try uploading a large attachment like this one.

Fixes #1702

@stackblitz
Copy link

stackblitz bot commented Feb 25, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@netlify
Copy link

netlify bot commented Feb 25, 2023

Deploy Preview for elk-docs canceled.

Name Link
🔨 Latest commit 295e29f
🔍 Latest deploy log https://app.netlify.com/sites/elk-docs/deploys/63fe7736fcf28500092b7101

@netlify
Copy link

netlify bot commented Feb 25, 2023

Deploy Preview for elk-zone ready!

Name Link
🔨 Latest commit 295e29f
🔍 Latest deploy log https://app.netlify.com/sites/elk-zone/deploys/63fe7736b4a26d0008cb548b
😎 Deploy Preview https://deploy-preview-1824--elk-zone.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@zaidhaan
Copy link
Contributor Author

Hmm, works fine in dev locally but it looks like the Content Service Policy is blocking image blobs in the preview.
image

Also the error message doesn't look too great, yikes. Error handling could be improved
image

Shouldn't take too long to fix so I won't turn this into a draft just yet.

@zaidhaan
Copy link
Contributor Author

Okay, all done.

CSP blob issue fixed. Resizing works.
image

As for the error message, per my last commit I just made it such that if resizing fails for whatever reason, then just attempt to upload the original file anyway. The user need not know about the details of a resizing failure, but it will still be logged in the console.

Copy link
Member

@patak-dev patak-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work @zaidhaan, let's merge it so we get some more testing on https://main.elk.zone

@patak-dev patak-dev merged commit 32eaee8 into elk-zone:main Feb 28, 2023
@zaidhaan zaidhaan deleted the resize-large-images branch February 28, 2023 22:46
DataDrivenMD pushed a commit to Distal-Labs/elk that referenced this pull request Mar 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cant upload larger images supported by other clients
2 participants