@Override
    public BaseB2Response upload(final Path file, final Local local, final BandwidthThrottle throttle,
                                 final StreamListener listener, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
        final long partSize;
        if(file.getType().contains(Path.Type.encrypted)) {
            // For uploads to vault part size must be a multiple of 32 * 1024. Recommended partsize from B2 API may not meet that requirement.
            partSize = PreferencesFactory.get().getLong("b2.upload.largeobject.size");
        }
        else {
            partSize = this.partSize;
        }
        return this.upload(file, local, throttle, listener, status, callback,
                partSize < status.getLength() ? partSize : PreferencesFactory.get().getLong("b2.upload.largeobject.size.minimum"));
    }
@Test
    public void testUpload() throws Exception {
        final Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));

        final Path test = new Path(bucket, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
        final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());

        // Each segment, except the last, must be larger than 100MB.
        final int length = 5 * 1000 * 1000 + 1;
        final byte[] content = RandomUtils.nextBytes(length);

        final OutputStream out = local.getOutputStream(false);
        IOUtils.write(content, out);
        out.close();
        final TransferStatus status = new TransferStatus();
        status.setLength(content.length);
        final Checksum checksum = new SHA1ChecksumCompute().compute(new ByteArrayInputStream(content), new TransferStatus());
        status.setChecksum(checksum);

        final B2VersionIdProvider fileid = new B2VersionIdProvider(session);
        final B2LargeUploadService upload = new B2LargeUploadService(session, fileid,
                new B2WriteFeature(session, fileid), 5 * 1000L * 1000L, 5);

        upload.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(),
                status, new DisabledConnectionCallback());
        final PathAttributes attr = new B2AttributesFinderFeature(session, fileid).find(test);
        assertNotEquals(Checksum.NONE, attr.getChecksum());
        assertEquals(checksum, attr.getChecksum());
        status.validate();
        assertTrue(status.isComplete());
        assertEquals(content.length, status.getResponse().getSize());

        assertTrue(new DefaultFindFeature(session).find(test));
        final InputStream in = new B2ReadFeature(session, fileid).read(test, new TransferStatus(), new DisabledConnectionCallback());
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
        new StreamCopier(status, status).transfer(in, buffer);
        in.close();
        buffer.close();
        assertArrayEquals(content, buffer.toByteArray());
        new B2DeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
        local.delete();
    }