imgur icon indicating copy to clipboard operation
imgur copied to clipboard

Migrate to only use the upload endpoint, Add video parameter support

Open Infinitay opened this issue 11 months ago • 3 comments

Is your feature request related to a problem? Please describe. Unable to upload videos larger than 10MB

Describe the solution you'd like

  • ~~When uploading an image or video, use the /image endpoint~~
    • Maybe not. Just noticed /image doesn't return useful info when trying to upload a video - the >10 MB video
  • Allow the user to specify either an image or video parameter as the Payload

Currently, users can't upload videos over 10 MB because regardless of the endpoint (/image or /upload) the image payload parameter is limited to 10 MB while the new video parameter has a limit of 200MB (https://apidocs.imgur.com/#c85c9dfc-7487-4de2-9ecd-66f727cf3139). By allowing users to specify whether they want to upload an image or video appropriately, not only would it be proper as opposed to sending a video as an image payload, but it would also allow for larger video files to be uploaded.

Additional context Another thing, I was looking at the code and I wanted to let you know that axios can handle the form data on its own now by specifying the object as a payload. In our case, just make sure to maintain the form content header. For example,

const postData = {
	video: fs.createReadStream("./video.mp4") as any,
	title: "Test",
	description: "Test description",
	name: "video.mp4",
	type: "file",
};
const response = await axios.post("https://api.imgur.com/3/image", postData, {
	headers: { Authorization: `Bearer ${client.credentials.accessToken}`, "content-type": "multipart/form-data;" },
});

I was going to try and make the changes myself, but I didn't want to potentially break anything since supposedly the tests aren't working. The main confusion was with

  for (const [key, value] of Object.entries(payload)) {
    const supportedUploadObjectTypes = ['base64', 'stream'];
    if (supportedUploadObjectTypes.indexOf(key) !== -1) {
      if (supportedUploadObjectTypes.indexOf(payload.type as string) !== -1) {
        form.append(key, payload);
      }
    } else if (value) {
      form.append(key, value);
    }
  }

Specifically the checks to append the payload. I don't see how form.append(key, payload); is ever reached because isn't if (supportedUploadObjectTypes.indexOf(key) !== -1) never met? Checking the Payload type definition, the key could never be base64 or stream unless I am missing something else.

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

Infinitay avatar Sep 10 '23 01:09 Infinitay