Java s3只允许从一个文件夹上载

Java s3只允许从一个文件夹上载,java,amazon-s3,aws-sdk,aws-java-sdk,Java,Amazon S3,Aws Sdk,Aws Java Sdk,我遇到的问题是,我只能从projects目录上传图像(/home/usr/workspace/project/~从这里~) 由于显而易见的原因,当我发布此功能时,这将不起作用。我不确定应该在哪里对其进行不同的配置。帮助我,你是我唯一的希望 @RequestMapping("/saveImage") public String getPreparedUploadUrl(@RequestParam File fileName, HttpSession session) throws IOExc

我遇到的问题是,我只能从projects目录上传图像(
/home/usr/workspace/project/~从这里~

由于显而易见的原因,当我发布此功能时,这将不起作用。我不确定应该在哪里对其进行不同的配置。帮助我,你是我唯一的希望

@RequestMapping("/saveImage")
public String getPreparedUploadUrl(@RequestParam File fileName, 
  HttpSession session) throws IOException, InterruptedException {
    java.util.Date expiration = new java.util.Date();
    long msec = expiration.getTime();
    msec += 1000 * 60 * 60; // Add 1 hour.
    expiration.setTime(msec);
    ObjectMetadata md = new ObjectMetadata();
    md.setContentType("image/jpg");
    md.setContentLength(fileName.length());
    md.setHeader(fileName.getName(), fileName.getAbsolutePath());
    File file = new File(fileName.getAbsolutePath());
    FileInputStream fis = new FileInputStream(file);
    byte[] content_bytes = IOUtils.toByteArray(fis);
    String md5 = new 
 String(Base64.encodeBase64(DigestUtils.md5(content_bytes)));
    md.setContentMD5(md5);


    GeneratePresignedUrlRequest generatePresignedUrlRequest = 
            new GeneratePresignedUrlRequest("wandering-wonderland-
images", fileName.getName());

    generatePresignedUrlRequest.setMethod(HttpMethod.PUT); 
    generatePresignedUrlRequest.setExpiration(expiration);


    URL s = 
 s3client.generatePresignedUrl(generatePresignedUrlRequest);

    try {

        UploadObject(s, fileName);

    } catch (IOException e) {
        e.printStackTrace();
    }
    session.setAttribute("saved", fileName + " has been saved!");
    return "redirect:/saved3";
}

// working, don't f@$# with it!
public static void UploadObject(URL url, File file) throws 
IOException, InterruptedException {

    HttpURLConnection connection=(HttpURLConnection) 
  url.openConnection();
    InputStream inputStream = new 
   FileInputStream(file.getAbsolutePath());
    connection.setDoOutput(true);
    connection.setRequestMethod("PUT");
    OutputStream out =
            connection.getOutputStream();

    byte[] buf = new byte[1024];
    int count;
    int total = 0;
    long fileSize = file.length();

    while ((count =inputStream.read(buf)) != -1)
    {
        if (Thread.interrupted())
        {
            throw new InterruptedException();
        }
        out.write(buf, 0, count);
        total += count;
        int pctComplete = new Double(new Double(total) / new 
Double(fileSize) * 100).intValue();

        System.out.print("\r");
        System.out.print(String.format("PCT Complete: %d", 
 pctComplete));
    }
    System.out.println();
    out.close();
    inputStream.close();

    int responseCode = connection.getResponseCode();
    System.out.println("Service returned response code " + 
      responseCode);
}

欢迎来到StackOverflow!与其粘贴整个程序,不如将其缩减到给您带来问题的相关部分?有关发布好问题的提示,请参阅。您还可以考虑使用代码来简化代码。您可以理解路径是如何工作的,并且每个进程的概念都有它当前工作目录的概念,并且不合格(非绝对)路径被解释为相对于CWD…对吗?如果非绝对路径是相对于cwd的。打电话给getAbsolutePath就不能解决这个问题吗?