Currently SDK primaly focuses on The UploadThing API Helper only.
The documintation below include basic usage considerations. Anything not listed below works similarly to the original docs.
maven
<dependency>
<groupId>org.chocodev.uploadthing</groupId>
<artifactId>core</artifactId>
<version>1.0.1</version> # please include latest version.
</dependency>
gradle
implementation group: 'org.chocodev.uploadthing', name: 'core', version: '1.0.1'
or other methods, that can be found at maven central
UTApi utApi = new UTApi(token); //v7 token only
utApi.uploadFiles(File);
Representation of the file for the upload.
UTFile File = UTFile.bulder()
.setBytes(bytes)
.setName(path.getFileName().toString())
.setSize(Files.size(path))
.setLastModified(Files.getLastModifiedTime(path).toMillis())
.setType("img/jpeg")
.setCustomId(customId)
.build();
Every UTApi request returns a custom UTResponse object.
UTResponse<DeleteResponse> response = utApi.deleteFiles(File);
if(response.hasException()){
// code if an exception occurred
}
if(response.isOk()){
// code on success
}
if(response.getStatus() == 404){
// ...
}
response.getBody(); // body of the response
response.throwIfException(); // throw the original exception
response.throwIfException((m)->new BadApiCallException(m)); // or your custom one.
Upload a file or files. You can also specify the type of some response data. When uploading several files, the response body will contain the upload count. (count of only successfully uploaded files)
UTResponse<UploadPerRequest<Long>> response = utApi.uploadFiles<Long>(File);
UTResponse<UploadPerRequest<Long>> response = utApi.uploadFiles(File, UploadOptions);
UTResponse<UploadResponse<Long>> response = utApi.uploadFiles(List.of(File, SecondFile), UploadOptions);
Delete a file or files by FileKey.
UTResponse<DeleteResponse> response = utApi.deleteFiles(FileKey);
UTResponse<DeleteResponse> response = utApi.deleteFiles(FileKey, DeleteOptions);
This object is very useful in cases when the rest API accepts custom IDs or file keys. It accepts one or several existing keys or can take keys from IUTFile class implementations (file representation from Rest API responses).
IUTFile ResponseFile = // UT rest api call.
FileKey.builder()
.setFileKey(ResponseFile)
.setFileKey("fileKey")
.setFileKey("secondKey", "thirdKey")
.build();
An interface exclusively for response representation of UploadThing files. It is implemented by subclasses of BasicFile.
The method requires the object that cannot be initialized.
In such cases, the object must have a static builder class that can be created either by calling the static method of that object or using a separate builder class.
How can i send a file?