Skip to content

Latest commit

 

History

History
96 lines (52 loc) · 2.67 KB

ReadME.md

File metadata and controls

96 lines (52 loc) · 2.67 KB

License: MIT

arduino-library-badge

ImgurUploader

imgur.com image/video upload library for ESP32

❓ What is it?

This library will let you upload images or videos to imgur.com using WiFi. It can read from a file (SD, SD_MMC, SPIFFS) or from a byte array. This library is heavily inspired from the Arduino Imgur library https://github.com/tinkerlog/Imgur

It has been totally rewritten to fit the ESP32's WiFiClientSecure requirements, extended to different mime types and sources, and finally adapted to imgur's API v3.

Big thanks to @tinkerlog for the inspiration.

🏗️ Install

For the lazy: search for "imgurUploader" in the Arduino library manager and click "install".

image

For the brave: download the the latest release from this repository and use the import option from the Arduino IDE sketch menu.

image

🛠️ Usage

  1. Get an imgur client ID

  2. Set the client ID in the sketch

    #define IMGUR_CLIENT_ID "your-imgur-client-id"
  3. Create an ImgurUploader instance

    ImgurUploader imgurUploader( IMGUR_CLIENT_ID );
  4. Connect to the WiFi

    WiFi.connect();
  5. Send the data

    int ret = imgurUploader.uploadFile( SD, "/pic.jpg" );
    // or
    int ret = imgurUploader.uploadBytes( byteArray, arrayLength, "pic.jpg", "image/jpeg" );
    // or
    int ret = imgurUploader.uploadStream( 12345678, &writeStreamCallback, "pic.jpg", "image/jpeg" );  
  6. Get the resulting imgur.com URL

    if( ret > 0 ) {
      Serial.println( imgurUploader.getURL() );
    } else {
      Serial.println( "Upload failed" );
    }

Callbacks

  • Upload progress: setProgressCallback( &yourProgressFunction ) where void yourProgressFunction( byte progress ) prints a value between 0 and 100

  • Stream Write: imgurUploader.uploadStream( streamSize, &writeStreamCallback ) where writeStreamCallback( Stream* client ) writes the image data by chunks (total size must be streamSize bytes exactly!)