FileStorageAppComponent
Required to implement a file-storage component. File storage writes a file from to remote source such as a remote file system (FTP) or a SaaS application.
Source: Github
Example:
package my.org.components;
import io.dexi.service.AppContext;
import io.dexi.service.components.AppComponent;
import io.dexi.service.components.FileStorageAppComponent;
import io.dexi.service.exceptions.UserErrorException;
import org.apache.commons.io.IOUtils;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@AppComponent("write-file-to-my-app")
public class MyAppFileStorageAppComponent implements FileStorageAppComponent<MyAppConfig, MyComponentConfig> {
@Override
public Class<MyComponentConfig> getComponentConfigClass() {
return MyComponentConfig.class;
}
@Override
public void write(AppContext<MyAppConfig, MyComponentConfig> ctxt, HttpServletRequest request) {
File file = new File("some-file.txt");
try(OutputStream out = new FileOutputStream(file)) {
IOUtils.copyLarge(request.getInputStream(), out);
} catch (IOException e) {
throw new UserErrorException("Failed to read file" ,e );
}
}
}
components:
- name: write-file-to-my-app
type: file-storage
title: Write a file to my app
specification:
endpoint: # Will invoke MyAppFileStorageAppComponent::write
url: "${baseUrl}/dexi/file/storage/write"
method: POST
Updated about 5 years ago