mirror of
https://github.com/iminet/ImgBBApi.git
synced 2026-10-03 12:24:54 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c69898ed0b | ||
|
|
1a84a39be0 | ||
|
|
7accf08959 | ||
|
|
08a6f61c9f | ||
|
|
0b16a55693 | ||
|
|
545a4b29eb |
@@ -0,0 +1,99 @@
|
||||
name: Publish NuGet package
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
id-token: write
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Verify publishing credentials
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
shell: bash
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
NUGET_USER: ${{ secrets.NUGET_USER }}
|
||||
run: |
|
||||
if [[ -z "$GITHUB_TOKEN" ]]; then
|
||||
echo "GitHub Packages token is not available."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z "$NUGET_USER" ]]; then
|
||||
echo "The NUGET_USER secret is missing or empty."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Set up .NET SDKs
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: |
|
||||
5.0.x
|
||||
6.0.x
|
||||
7.0.x
|
||||
8.0.x
|
||||
10.0.x
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore ImgBBApi.csproj
|
||||
|
||||
- name: Create NuGet package
|
||||
shell: bash
|
||||
run: |
|
||||
PACKAGE_VERSION_ARGS=()
|
||||
if [[ "$GITHUB_REF_TYPE" == "tag" ]]; then
|
||||
PACKAGE_VERSION_ARGS=(-p:PackageVersion="${GITHUB_REF_NAME#v}")
|
||||
fi
|
||||
|
||||
dotnet pack ImgBBApi.csproj \
|
||||
--configuration Release \
|
||||
--no-restore \
|
||||
--output ./artifacts \
|
||||
-p:GeneratePackageOnBuild=false \
|
||||
"${PACKAGE_VERSION_ARGS[@]}"
|
||||
|
||||
- name: Upload package artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ImgBBApi-nuget-package
|
||||
path: ./artifacts/*.nupkg
|
||||
if-no-files-found: error
|
||||
|
||||
- name: Publish to GitHub Packages
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
run: |
|
||||
for package in ./artifacts/*.nupkg; do
|
||||
dotnet nuget push "$package" \
|
||||
--source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" \
|
||||
--api-key "${{ secrets.GITHUB_TOKEN }}" \
|
||||
--skip-duplicate
|
||||
done
|
||||
|
||||
- name: NuGet login
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
uses: NuGet/login@v1
|
||||
id: nuget-login
|
||||
with:
|
||||
user: ${{ secrets.NUGET_USER }}
|
||||
|
||||
- name: Publish to NuGet.org
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
run: |
|
||||
for package in ./artifacts/*.nupkg; do
|
||||
dotnet nuget push "$package" \
|
||||
--source "https://api.nuget.org/v3/index.json" \
|
||||
--api-key "${{ steps.nuget-login.outputs.NUGET_API_KEY }}" \
|
||||
--skip-duplicate
|
||||
done
|
||||
+6
-1
@@ -29,7 +29,12 @@ namespace Iminetsoft
|
||||
/* SORGU GONDERDIK VE JSON RESPONSE-U ELDE ETDIK: */
|
||||
string requestUrl = $"https://api.imgbb.com/1/upload?key={ApiKey}";
|
||||
MultipartFormDataContent content = new MultipartFormDataContent();
|
||||
string base64OfImage = Convert.ToBase64String(File.ReadAllBytes(imagePath));
|
||||
|
||||
// Temporary solution
|
||||
string base64OfImage = File.Exists(imagePath) ? Convert.ToBase64String(File.ReadAllBytes(imagePath))
|
||||
: imagePath.Trim();
|
||||
|
||||
|
||||
content.Add(new StringContent(base64OfImage), "image");
|
||||
content.Add(new StringContent(Path.GetFileNameWithoutExtension(imagePath)), "name");
|
||||
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUrl) { Content = content };
|
||||
|
||||
+8
-7
@@ -1,14 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
|
||||
<TargetFrameworks>net5.0;net6.0;net7.0;net8.0;net10.0</TargetFrameworks>
|
||||
<Nullable>disable</Nullable>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>ImgBBApi</RootNamespace>
|
||||
<AssemblyName>ImgBBApi</AssemblyName>
|
||||
<PackageReleaseNotes>Added package icon</PackageReleaseNotes>
|
||||
<Version>1.0.2</Version>
|
||||
<AssemblyVersion>1.0.2</AssemblyVersion>
|
||||
<FileVersion>1.0.2</FileVersion>
|
||||
<Deterministic>False</Deterministic>
|
||||
<AssemblyVersion>1.0.6</AssemblyVersion>
|
||||
<Version>$(AssemblyVersion)</Version>
|
||||
<FileVersion>$(AssemblyVersion)</FileVersion>
|
||||
<Authors>iminet</Authors>
|
||||
<Product>C# library for ImgBB</Product>
|
||||
<PackageId>Iminetsoft.ImgBBApi</PackageId>
|
||||
@@ -16,15 +17,15 @@
|
||||
<PackageProjectUrl>https://github.com/iminet/ImgBBApi</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/iminet/ImgBBApi</RepositoryUrl>
|
||||
<PackageTags>dotnet ImgBB, image, imageupload, API</PackageTags>
|
||||
<PackageReadmeFile>Readme.md</PackageReadmeFile>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<Description>C# library for ImgBB</Description>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<!--<GeneratePackageOnBuild>true</GeneratePackageOnBuild>-->
|
||||
<CheckEolTargetFramework>false</CheckEolTargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="Readme.md" Pack="true" PackagePath="\"></None>
|
||||
<None Include="README.md" Pack="true" PackagePath="\"></None>
|
||||
<None Include="Resources\imgbb.png" Pack="true" PackagePath="\"></None>
|
||||
<None Include="Resources\imgbb-invert.png" Pack="true" PackagePath="\"></None>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1 +1,122 @@
|
||||
# ImgBBApi
|
||||
|
||||
A lightweight C# client library for uploading images to [ImgBB](https://imgbb.com/) from .NET applications.
|
||||
|
||||
`ImgBBApi` accepts either local image file paths or Base64-encoded image data and returns the direct URLs generated by ImgBB.
|
||||
|
||||
## Features
|
||||
|
||||
- Upload one or more local image files
|
||||
- Upload Base64-encoded image content
|
||||
- Async API built on `HttpClient`
|
||||
- Multi-targets .NET 5, .NET 6, .NET 7, and .NET 8
|
||||
|
||||
## Installation
|
||||
|
||||
Install the package from NuGet:
|
||||
|
||||
```bash
|
||||
dotnet add package Iminetsoft.ImgBBApi
|
||||
```
|
||||
|
||||
Or use the NuGet Package Manager Console:
|
||||
|
||||
```powershell
|
||||
Install-Package Iminetsoft.ImgBBApi
|
||||
```
|
||||
|
||||
## Getting an ImgBB API key
|
||||
|
||||
1. Sign in to [ImgBB](https://imgbb.com/).
|
||||
2. Create an API key from the [ImgBB API key page](https://api.imgbb.com/).
|
||||
3. Keep the key private—do not commit it to source control.
|
||||
|
||||
For example, store it in an environment variable:
|
||||
|
||||
```bash
|
||||
export IMGBB_API_KEY="your-api-key"
|
||||
```
|
||||
|
||||
## How to use
|
||||
|
||||
### Upload local files
|
||||
|
||||
```csharp
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Iminetsoft;
|
||||
|
||||
var apiKey = Environment.GetEnvironmentVariable("IMGBB_API_KEY");
|
||||
var client = new ImgBBApi(apiKey);
|
||||
|
||||
var imageUrls = await client.UploadImgbbAsync(new List<string>
|
||||
{
|
||||
@"C:\\images\\photo-1.png",
|
||||
@"C:\\images\\photo-2.jpg"
|
||||
});
|
||||
|
||||
foreach (var imageUrl in imageUrls)
|
||||
{
|
||||
Console.WriteLine(imageUrl);
|
||||
}
|
||||
```
|
||||
|
||||
### Upload Base64 image data
|
||||
|
||||
Pass a Base64-encoded image string instead of a file path:
|
||||
|
||||
```csharp
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Iminetsoft;
|
||||
|
||||
var apiKey = Environment.GetEnvironmentVariable("IMGBB_API_KEY");
|
||||
var client = new ImgBBApi(apiKey);
|
||||
|
||||
var base64Image = Convert.ToBase64String(
|
||||
await File.ReadAllBytesAsync("photo.png"));
|
||||
|
||||
var imageUrls = await client.UploadImgbbAsync(new List<string>
|
||||
{
|
||||
base64Image
|
||||
});
|
||||
|
||||
Console.WriteLine(imageUrls[0]);
|
||||
```
|
||||
|
||||
## API reference
|
||||
|
||||
### `ImgBBApi(string apiKey)`
|
||||
|
||||
Creates a client with the ImgBB API key used for all upload requests.
|
||||
|
||||
### `Task<List<string>> UploadImgbbAsync(List<string> imagePaths)`
|
||||
|
||||
Uploads each supplied value to ImgBB and returns a list of image URLs.
|
||||
|
||||
Each item may be:
|
||||
|
||||
- a path to an existing local image file; or
|
||||
- a Base64-encoded image string.
|
||||
|
||||
The returned list follows the successful upload order. If an upload fails, the current implementation suppresses the exception and may return an empty or partial list.
|
||||
|
||||
## Requirements
|
||||
|
||||
- .NET 5.0, 6.0, 7.0, or 8.0
|
||||
- A valid ImgBB API key
|
||||
- Internet access to `https://api.imgbb.com`
|
||||
|
||||
## Notes
|
||||
|
||||
- ImgBB controls its own upload limits, retention, and content policies. Consult the [ImgBB API documentation](https://api.imgbb.com/) for the current terms and limits.
|
||||
- Treat API keys and uploaded image URLs according to your application's security and privacy requirements.
|
||||
|
||||
## Origin
|
||||
|
||||
This project is based on [qalibqurbanov/Imager](https://github.com/qalibqurbanov/Imager).
|
||||
|
||||
## License
|
||||
|
||||
No license is currently specified in this repository. Add a license file before distributing or reusing the project under explicit terms.
|
||||
|
||||
Reference in New Issue
Block a user