【发布时间】:2013-07-15 19:39:55
【问题描述】:
希望你能帮助我。我找不到任何问题的答案
我有这部分 JSP 代码:
<html:form action="/restricted/gallery/GalleryUpload" method="post" enctype="multipart/form-data">
<table width="98%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td width="21%" align="right" class="input_head">Upload Image: </td>
<td class="size12_text_red"><html:file property="file" styleId="File"/> <br/>(Contents of zip files will be extracted and uploaded individually)</td>
</tr>
<tr align="center">
<td colspan="4"><input name="upload2" type="submit" id="upload" class="butt_style" value="Submit"/></td>
</tr>
</table>
然后我将数据传递给 Java 类:
else if (req.getParameter("upload2") != null) {
String existingBucketName = "BUCKETNAME";
String filePath = cform.getFile().toString();
String keyName = filePath.substring(filePath.lastIndexOf("/")+1);
String amazonFileUploadLocationOriginal=existingBucketName+"/gallery/"+user.getOwnerId()+"/album_name";
AmazonS3 s3Client = new AmazonS3Client(new PropertiesCredentials(SouthdownsServicesAction.class.getResourceAsStream("AwsCredentials.properties")));
FileInputStream stream = new FileInputStream(filePath);
ObjectMetadata objectMetadata = new ObjectMetadata();
PutObjectRequest putObjectRequest = new PutObjectRequest(amazonFileUploadLocationOriginal, keyName, stream, objectMetadata);
PutObjectResult result = s3Client.putObject(putObjectRequest);
所以我想要做的是,在 filePath 部分中,我试图将完整路径从您选择的输入表单文件传递到那里,但它根本不起作用。如果我将该 filePath 更改为位于我的本地计算机上的简单路径,它可以正常工作。像下面这样:
String filePath = "C://Pics//logo.jpg";
如果我上传的是 ZIP 文件而不是图片,它将如何提取 ZIP 内容并单独上传所有文件?
提前致谢
【问题讨论】:
标签: java html forms file upload