UploadThing.Core
0.1.0
dotnet add package UploadThing.Core --version 0.1.0
NuGet\Install-Package UploadThing.Core -Version 0.1.0
<PackageReference Include="UploadThing.Core" Version="0.1.0" />
paket add UploadThing.Core --version 0.1.0
#r "nuget: UploadThing.Core, 0.1.0"
// Install UploadThing.Core as a Cake Addin #addin nuget:?package=UploadThing.Core&version=0.1.0 // Install UploadThing.Core as a Cake Tool #tool nuget:?package=UploadThing.Core&version=0.1.0
UploadThing
"A thing for uploading files.", now in DotNet ecosystem.
var options = new UploadThing.Core.UploadThingOptions(
UPLOADTHING_SECRET: "BETTER_READ_FROM_SECRET"
);
var uploader = new UploadThing.Core.Uploader(options).
MaxSize(10). // 10 MB
Middleware(req =>
{
if(user == null)
throw new Exception("User not authenticated"); //upload process will be halted
return new { message = "a great big metadata" }; // whatever is returned, will be boxed for Metadata
}).
OnUploadPrepare(file =>
{
// the file is ready for upload, that means, we got Presigned URL for S3.
// assuming different workflows, it may come handy.
// for example, if you want your your client to handle uploading
// (perhaps the main motivation?)
Console.WriteLine("URL: " + file.Url);
Console.WriteLine("Name: " + file.Name);
Console.WriteLine("Metadata: " + JsonConvert.SerializeObject(file.Metadata));
}).
OnUploadComplete(file =>
{
// the file is uploaded to S3.
// the `file` type is same as the `file` type in OnUploadPrepare
Console.WriteLine("It's uploaded to S3.");
});
var fileStream = File.OpenRead("A_VALID_FILE_PATH");
var fileDetails = new UploadThing.Core.FileDetails(
FileName: Path.GetFileName(fileStream.Name),
FileType: UploadThing.Core.UtUtils.GetFileType(fileStream.Name),
CallbackSlug: "ut_example_console",
CallbackUrl: "https://example.com/uploadthing"
);
// if you just want to get presigned url infos and use them somewhere else,
var presignedResponse = await uploader.PrepareUpload(fileDetails);
// if you just want to directly upload the file (it works even if you call PrepareUpload() before it)
var utFile = await uploader.UploadAsync(fileStream, fileDetails);
// or, if you have presigned url and you want to upload to S3 using that -
var downloadUrl = await S3Uploader.UploadAsync(presignedResponse, fileStream);
Examples
Examples ain't ready yet properly, but feel free to look around and improve.
UploadThing.Example.AspNetCoreWebAPI
A simple api, an example how you might use it in your API.
[POST] /api/upload/prepare
: to prepare S3's presigned URL, that can be used from your client application to upload directly to S3.
[POST] /api/upload/s3upload
: simple endpoint to upload a file using presigned url response and file. This is just for demonstration how presigned url can be used to upload file.
[POST] /api/upload/webhook
: this the endpoint you can pass in callbackUrl
. This will be invoked by UT's server, when file is uploaded to s3. For better understanding, please overview this diagram.
Code: ./UploadThing.Example.AspNetCoreWebAPI/
UploadThing.Example.Console
A simple console application that upload an image.
Code: ./UploadThing.Example.Console/
UploadThing.Example.AspNetCoreMVC
A simple example in ASP.NET MVC, demonstrating AJAX Form Upload and POST Form Upload.
Code: ./UploadThing.Example.AspNetCoreMVC/
UploadThing.Example.Unity
Upcoming...
Exception Handling
To handle exceptions related to Presigned URL or any action toward UploadThing server, we may get best use of -
catch (UploadThingException utException)
{
Console.WriteLine("Error when preparing for upload to UT server - " + utException.Message);
}
To handle exception related uploading to AWS S3 -
catch (UploadThingS3Exception s3Exception)
{
Console.WriteLine("Error when uploading to S3 - " + s3Exception.ErrorCode);
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.1.0 | 190 | 5/27/2023 |