From e2fddb18d65de832062d4d8f057f71a8d066f9ca Mon Sep 17 00:00:00 2001 From: tobozo Date: Tue, 10 Aug 2021 18:20:10 +0200 Subject: [PATCH 1/2] Fixed sendImageData() with SOURCE_BYTE_ARRAY (see #1) --- src/ImgurUploader.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ImgurUploader.cpp b/src/ImgurUploader.cpp index 15c9ff9..18bc1ef 100644 --- a/src/ImgurUploader.cpp +++ b/src/ImgurUploader.cpp @@ -37,7 +37,7 @@ #define IMGUR_UPLOAD_API_URL "/3/image" #define IMGUR_UPLOAD_API_DOMAIN "api.imgur.com" #define IMGUR_URL_MASK "https://imgur.com/%s" -#define IMGUR_BUFFSIZE 512 +#define IMGUR_BUFFSIZE 4096 #define BOUNDARY "blah-blah-oz" #define HEADER "--" BOUNDARY #define FOOTER "--" BOUNDARY "--" @@ -69,13 +69,13 @@ int ImgurUploader::uploadFile( fs::FS &fs, const char* path ) { const char* fileName = _sourceFile.name(); _arrayLen = _sourceFile.size(); const char* mimeType = getMimeType( fileName ); - return upload( fileName, mimeType ); + return upload( fileName, mimeType ); } int ImgurUploader::uploadBytes( const uint8_t* byteArray, size_t arrayLen, const char* imageName, const char* imageMimeType ) { _source = SOURCE_BYTE_ARRAY; - _byteArray = (uint8_t*)_byteArray; + _byteArray = (uint8_t*)byteArray; _arrayLen = arrayLen; const char* mimeType = getMimeType( imageName ); //String fileName = String( imageName ); @@ -137,7 +137,11 @@ int ImgurUploader::upload( const char* imageName, const char* imageMimeType ) { void ImgurUploader::sendImageData() { - uint8_t buf[IMGUR_BUFFSIZE]; + uint8_t *buf = (uint8_t*)calloc( IMGUR_BUFFSIZE+1, sizeof(uint8_t) ); + if( buf == NULL ) { + log_e("Can't alloc %d bytes, aborting", IMGUR_BUFFSIZE+1); + return; + } size_t packets = 0; size_t _progress = 0; switch( _source ) { @@ -193,6 +197,7 @@ void ImgurUploader::sendImageData() { } break; } + free(buf); } From 4b349280654ea5224b768ef4dff0023d26477ea4 Mon Sep 17 00:00:00 2001 From: tobozo Date: Tue, 10 Aug 2021 18:20:18 +0200 Subject: [PATCH 2/2] raising version --- library.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library.properties b/library.properties index f039056..a8adfb9 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ESP32-imgur-uploader -version=1.0.2 +version=1.0.3 author=tobozo maintainer=tobozo@noreply.github.com sentence=imgur.com Image/Video uploader @@ -9,4 +9,4 @@ url=https://github.com/tobozo/ImgurUploader/ architectures=esp32 includes=ImgurUploader.h depends=ArduinoJSON - +