Php

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.

Related Post

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

View Comments

Recent Posts

Configure and Retrieve S3 Information Using Laravel PHP-AWS-SDK

This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More

3 months ago

What is the Purpose of php_eol in PHP?

in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More

9 months ago

Laravel Table Relationship Methods With Example

This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More

9 months ago

Exploring the Power of Laravel Eloquent Join?

We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More

9 months ago

Quick and Easy Installation of Laravel Valet

in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More

10 months ago

What is Laravel Soft Delete and How Does it Work?

I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More

10 months ago

Categories