3

I am using the Imgur API to upload images to albums, as part of a Reddit bot. However, when I try to upload MP4 files I get an error: "File type invalid (1)". Uploading the exact same MP4 file using the website works just fine.

I am using this endpoint to upload the file: POST https://api.imgur.com/3/image

https://apidocs.imgur.com/#c85c9dfc-7487-4de2-9ecd-66f727cf3139

John Doe III
  • 33
  • 1
  • 3

3 Answers3

2

The above comment is no longer correct -- You can indeed upload an MP4 using Imgur API

import requests

url = "https://api.imgur.com/3/upload"

payload = {'album': 'ALBUMID',
'type': 'file',
'disable_audio': '0'}
files = [
  ('video', open('/path/to/Video.mp4','rb'))
]
headers = {
  'Authorization': 'Bearer BEARERTOKENHERE'
}

response = requests.request("POST", url, headers=headers, data = payload, files = files)

print(response.text.encode('utf8'))

The above works for me and uploads successfully. Something to note though, I have not figured out how to make the upload tied to my account, or within a specific album. It seems to be ignoring the album_id field. In other words, despite using the Bearer token, it appears to be navigating the API "anonymously".

Vizzyy
  • 522
  • 3
  • 11
  • 1
    Note that `https://api.imgur.com/3/upload` endpoint does not work for client-side Javascript integration due to the lack of CORS. You have to use `https://api.imgur.com/3/image` endpoint which does not accept video files. – Semra Jul 15 '21 at 14:26
  • @Semra imgur and their useless api – rockr101 Sep 06 '22 at 23:23
1

From the imgur Help site, located here and last updated 2 months ago:

https://help.imgur.com/hc/en-us/articles/115000083326-What-files-can-I-upload-What-is-the-size-limit-

File Types

If you need help learning how to upload on Imgur, check out this help article. You can upload any of the following files: JPEG, PNG, GIF, APNG, TIFF, MOV (desktop website only), MP4 (desktop website only)

Imgur doesn't currently support uploads in the following formats: WEBM GIFV

Explicitly, MP4s are only currently supported as uploaded manually via the website directly.

Unfortunately, that means imgur does not support MP4 types through any method other than the Desktop site at this current time.

Community
  • 1
  • 1
gravity
  • 2,175
  • 2
  • 26
  • 34
  • Ah, I saw that but figured they meant to distinguish it from the mobile apps. Thought the website was using their own API as well. Thanks though! – John Doe III Jan 31 '19 at 20:15
1

I agree with a comment above. Now it is works great. Even you can upload the video without authorization. Just using a POST method https://api.imgur.com/3/upload. Pass a video file in body with image key. That's all.

Example in Postman

enter image description here

Dyno Cris
  • 1,823
  • 1
  • 11
  • 20