How To Upload Video Using imgur API

in this tutorial, We’ll upload an mp4 video using imgur api. we will show you how to upload videos to Imgur via API and get video links from Imgur API using Python.

The Imgur API provides a programmatic approach to upload and manage images/videos on the Imgur server. The Imgur API is a REST API service that takes HTTP queries and provides JSON replies. You can integrate the Imgur API using any programming language.

Also checkout other related tutorials,

Each request must be authorized and Client ID is required to be passed with an authorization header in the Imgur API request.

'Authorization: Client-ID imgur-app-client-id'

What’s Imgur

Imgur is an internet platform for sharing and hosting images and videos. Without hosting the photographs on your server, you can share them online using Imgur.

Hosting the image on Imgur is the ideal option to use it without hosting it on the server if your online application has the ability to upload images and you want to maximize server space. The image files can be posted to Imgur and displayed on the website using an Imgur image link.

How To upload a video using Imgur API

We’ll use /upload API that will help to upload videos.

The api:

https://api.imgur.com/3/upload
Method : POST

Accepted Video Formats

  • video/mp4
  • video/webm
  • video/x-matroska
  • video/quicktime
  • video/x-flv
  • video/x-msvideo
  • video/x-ms-wmv
  • video/mpeg

How To Register Application

You need to register your application and generate the client ID. All HTTP requests for uploading images to Imgur must include the client_id in the authorization header and this would also let you upload images anonymously without the image being tied to your personal Imgur account.

You need to follow the below steps to authenticate :

  • Create an Imgur account and sign in.
  • Register an application from the Imgur OAuth Client page – https://api.imgur.com/oauth2/addclient
  • On successful App registration, the Client ID and Client secret will be generated
  • if you have already registered the app, You can get the Client ID from the App Settings page as well (https://imgur.com/account/settings/apps).

Source code to upload a video using API

import requests

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

payload = {'album': 'album_id',
'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 code will uploads the video 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.

References:

You can get more details from imgur Api

2 thoughts on “How To Upload Video Using imgur API

  1. I wanted to upload a video to imgur using the api and then get the link of where that video gets uploaded. Could you please guide on how to do that?

Leave a Reply

Your email address will not be published.