io.vertx.core.http.HttpServerFileUpload Java Examples

The following examples show how to use io.vertx.core.http.HttpServerFileUpload. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DiskFileUpload.java    From wisdom with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a temporary file.
 *
 * @return a new Temp File from getDiskFilename(), default prefix, postfix and baseDirectory
 */
static synchronized File tempFile(HttpServerFileUpload upload) {
    String newpostfix;
    String diskFilename = new File(upload.filename()).getName();
    newpostfix = '_' + diskFilename;
    File tmpFile;
    try {
        if (baseDirectory == null) {
            // create a temporary file
            tmpFile = File.createTempFile(prefix, newpostfix);
        } else {
            tmpFile = File.createTempFile(prefix, newpostfix, new File(
                    baseDirectory));
        }
        if (deleteOnExitTemporaryFile) {
            tmpFile.deleteOnExit();
        }
        return tmpFile;
    } catch (IOException e) {
        // Really bad, can't create the tmp file.
        throw new IllegalStateException(e);
    }

}
 
Example #2
Source File: ResumingRequestWrapper.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public HttpServerRequest uploadHandler(Handler<HttpServerFileUpload> handler) {
    delegate.uploadHandler(handler);
    if (!userSetState) {
        delegate.resume();
    }
    return this;
}
 
Example #3
Source File: MixedFileUpload.java    From wisdom with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an instance of {@link org.wisdom.framework.vertx.file.VertxFileUpload}.
 *
 * @param vertx     the Vert.X instance
 * @param upload    the upload object
 * @param limitSize the threshold. If the amount of uploaded data is below this limit,
 *                  {@link org.wisdom.framework.vertx.file.MemoryFileUpload} is used to backend the uploaded file.
 *                  Otherwise, it uses a {@link org.wisdom.framework.vertx.file.DiskFileUpload}.
 */
public MixedFileUpload(final Vertx vertx,
                       final HttpServerFileUpload upload,
                       final long limitSize,
                       final long maxSize,
                       final Handler<Result> errorHandler) {
    super(upload, errorHandler);
    delegate = new MemoryFileUpload(upload, errorHandler);

    upload.exceptionHandler(event -> LoggerFactory.getLogger(MixedFileUpload.class)
            .error("Cannot read the uploaded item {} ({})", upload.name(), upload.filename(), event))
            .endHandler(event -> delegate.close())
            .handler(
                    event -> {
                        if (event != null) {
                            // We are still in memory.
                            if (delegate instanceof MemoryFileUpload) {
                                MemoryFileUpload mem = (MemoryFileUpload) delegate;
                                checkSize(mem.buffer.length() + event.length(), maxSize, upload);
                                if (mem.buffer.length() + event.length() > limitSize) {
                                    // Switch to disk file upload.
                                    DiskFileUpload disk = new DiskFileUpload(vertx, upload, errorHandler);
                                    // Initial push (mem + current buffer)
                                    disk.push(mem.buffer.appendBuffer(event));
                                    // No cleanup required for the memory based backend.
                                    delegate = disk;

                                    // the disk based implementation use a pump.
                                } else {
                                    delegate.push(event);
                                }
                            }
                        }
                    }
            );
}
 
Example #4
Source File: ForwardedServerRequestWrapper.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public HttpServerRequest uploadHandler(Handler<HttpServerFileUpload> handler) {
    delegate.uploadHandler(handler);
    return this;
}
 
Example #5
Source File: AbstractRequestWrapper.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public HttpServerRequest uploadHandler(Handler<HttpServerFileUpload> handler) {
    delegate.uploadHandler(handler);
    return this;
}
 
Example #6
Source File: FileUploadImpl.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
public FileUploadImpl(String uploadedFileName, HttpServerFileUpload upload) {
  this.uploadedFileName = uploadedFileName;
  this.upload = upload;
}
 
Example #7
Source File: MixedFileUpload.java    From wisdom with Apache License 2.0 3 votes vote down vote up
/**
 * Checks whether we exceed the max allowed file size.
 *
 * @param newSize the expected size once the current chunk is consumed
 * @param maxSize the max allowed size.
 * @param upload  the upload
 */
private void checkSize(long newSize, long maxSize, HttpServerFileUpload upload) {
    if (maxSize >= 0 && newSize > maxSize) {
        upload.handler(null);
        report(new IllegalStateException("Size exceed allowed maximum capacity"));
    }
}
 
Example #8
Source File: DiskFileUpload.java    From wisdom with Apache License 2.0 2 votes vote down vote up
/**
 * Creates an instance of {@link org.wisdom.framework.vertx.file.DiskFileUpload}.
 *
 * @param vertx        the Vert.X instance
 * @param upload       the Vert.X file upload object
 * @param errorHandler the error handler
 */
public DiskFileUpload(Vertx vertx, HttpServerFileUpload upload, Handler<Result> errorHandler) {
    super(upload, errorHandler);
    this.file = tempFile(upload);
    this.vertx = vertx;
}
 
Example #9
Source File: MemoryFileUpload.java    From wisdom with Apache License 2.0 2 votes vote down vote up
/**
 * Creates an instance of {@link org.wisdom.framework.vertx.file.MemoryFileUpload}.
 *
 * @param upload       the Vert.X file upload object
 * @param errorHandler the error handler
 */
public MemoryFileUpload(HttpServerFileUpload upload, Handler<Result> errorHandler) {
    super(upload, errorHandler);

}
 
Example #10
Source File: VertxFileUpload.java    From wisdom with Apache License 2.0 2 votes vote down vote up
/**
 * Creates the {@link org.wisdom.framework.vertx.file.VertxFileUpload}.
 *
 * @param upload       the {@link HttpServerFileUpload} that is uploaded.
 * @param errorHandler the error handler.
 */
protected VertxFileUpload(HttpServerFileUpload upload, Handler<Result> errorHandler) {
    this.upload = upload;
    this.errorHandler = errorHandler;
}