UploadSrImg Issues
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- typescript
- Domain
- api, documentation
Research direction
Start with the UploadSrImgRequest definition and @devvit/protos/types/devvit/plugin/redditapi/subreddits/subreddits_msg.js around line 1854, then compare them with the supplied testUploadSrImg example. Reproduce the upload error if possible and verify how the image payload is represented. Done means the documented interface matches the implementation and the file encoding behavior is established or corrected.
Written by the indexing model from the issue text.
Description
The documentation on UploadSrImgRequest is wrong, and the header field is redundant/obsolete. It should look like this:
export interface UploadSrImgRequest {
/** file upload with maximum size of 500 KiB */
file: string;
/** one of png or jpg (default: png) */
imgType: 'png' | 'jpg';
/** a valid subreddit image name */
name: string;
/* one of (img, header, icon, banner) */
uploadType: 'img' | 'header' | 'icon' | 'banner';
/** the name of the subreddit */
subreddit: string;
}
I'm currently getting an error fetching the image to upload (HTTP request to domain: styles.redditmedia.com timed out with error: context deadline exceeded), but previously I've gotten a different error:
{
errors: [ 'IMAGE_ERROR' ],
imgSrc: '',
errorsValues: [ 'Invalid image or general image error' ]
}
I assume this is due to the encoding of the image data, but I'm not sure if it's because of my code, or because the upload code is writing the image data as a string instead of bytes (@devvit/protos/types/devvit/plugin/redditapi/subreddits/subreddits_msg.js line 1854). If it should be writing the data as bytes, then the file field in UploadSrImgRequest should have the type Uint8Array | string.
Test code:
import { Devvit } from '@devvit/public-api';
import { getMetadata } from '@devvit/runtimes/plugins/helpers.js';
import { Subreddits } from '@devvit/runtimes/plugins/redditapi/Subreddits.js';
async function testUploadSrImg(imageUrl: string, imageName: string, subredditName: string) {
const imageType = imageUrl.slice(-3);
if (imageType != 'png' && imageType != 'jpg') {
return;
}
const imageData = await fetch(imageUrl).then(response => {
return response.ok ? response.arrayBuffer() : null;
});
if (!imageData) {
return;
}
await ((Devvit as any).redditAPIPlugins.Subreddits as Subreddits).UploadSrImg(
{
file: Buffer.from(imageData).toString('binary'),
header: 0,
imgType: imageType,
name: imageName,
uploadType: 'img',
subreddit: subredditName
},
getMetadata()
);
}
- Dominant language
- TypeScript
- Stars
- 210
- Forks
- 88
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from reddit/devvit
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 5/5 Over a week Newbie friendliness 42/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
area:tools bug good first issue help wanted priority:P2
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
TaewoooPark/Motifcode#14 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
newrelic-experimental/preflight#793 · 1 comment ·
-
bug 🐞
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
[Bounty proposal] fix(web): memory insights count an evening memory on the next day ($25 proposed) Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
BasedHardware/omi#15320 ·