Java Path File Name nio uploadFileToServer(InputStream input, String filename, String usercode, String basePath)

Here you can find the source of uploadFileToServer(InputStream input, String filename, String usercode, String basePath)

Description

upload File To Server

License

Apache License

Declaration

public static String uploadFileToServer(InputStream input, String filename, String usercode, String basePath)
        throws IOException, FileNotFoundException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

public class Main {
    private static String ALIYUN_BASE_PATH = "cloud:/ehome/dev/";
    private static String ALIYUN_URL = "https://img.1000.com";

    public static String uploadFileToServer(InputStream input, String filename, String usercode)
            throws IOException, FileNotFoundException {
        return uploadFileToServer(input, filename, usercode, ALIYUN_BASE_PATH);
    }//from   w w  w . j  a v a 2s .c o m

    public static String uploadFileToServer(InputStream input, String filename, String usercode, String basePath)
            throws IOException, FileNotFoundException {
        Path cloudPath = Paths.get(URI.create(basePath + usercode + "/" + filename));
        Files.copy(input, cloudPath, StandardCopyOption.REPLACE_EXISTING);
        return ALIYUN_URL + cloudPath.toUri().toString();
    }
}

Related

  1. storeFile(String fileName, InputStream inputStream, Path targetPath)
  2. subDirectoryNames(final Path dir)
  3. toClassName(String path)
  4. toResourcePath(String fileName)
  5. unzipFile(String fileName, String targetPath)
  6. validateDockerfilePath(String name)
  7. which(Path path, String name)
  8. writeDataFile(final String resourceName, final Path sourcePath)
  9. writeFile(String pathname, String data)