|
|
|
@@ -12,7 +12,11 @@ import com.amazonaws.services.s3.AmazonS3ClientBuilder; |
|
|
|
import com.amazonaws.services.s3.model.CannedAccessControlList; |
|
|
|
import com.amazonaws.services.s3.model.ObjectMetadata; |
|
|
|
import com.amazonaws.services.s3.model.PutObjectRequest; |
|
|
|
import com.iformall.shiro.UserSession; |
|
|
|
import com.iformall.ueditor.define.State; |
|
|
|
import org.apache.shiro.SecurityUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
import org.springframework.web.multipart.MultipartHttpServletRequest; |
|
|
|
|
|
|
|
@@ -24,6 +28,8 @@ import java.util.UUID; |
|
|
|
|
|
|
|
public class Uploader { |
|
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass()); |
|
|
|
|
|
|
|
private HttpServletRequest request = null; |
|
|
|
private Map<String, Object> conf = null; |
|
|
|
|
|
|
|
@@ -46,7 +52,7 @@ public class Uploader { |
|
|
|
JSONObject stateJson = JSON.parseObject(state.toJSONString()); |
|
|
|
|
|
|
|
MultipartFile multiReq= ((MultipartHttpServletRequest) this.request).getFile("upfile"); |
|
|
|
String tenantId = "789"; //(String)SecurityUtils.getSubject().getSession().getAttribute(UserSession.tenantId); |
|
|
|
String tenantId = (String) SecurityUtils.getSubject().getSession().getAttribute(UserSession.tenantId); |
|
|
|
|
|
|
|
ObjectMetadata metadata = new ObjectMetadata(); |
|
|
|
metadata.setContentType(multiReq.getContentType()); |
|
|
|
@@ -80,27 +86,23 @@ public class Uploader { |
|
|
|
new PutObjectRequest(conf.get("bucketName").toString(), fileName, multiReq.getInputStream(), metadata) |
|
|
|
.withCannedAcl(CannedAccessControlList.PublicRead)); |
|
|
|
URL url = s3.getUrl(conf.get("bucketName").toString(), fileName); |
|
|
|
//logger.info(url.toString()); |
|
|
|
logger.info(url.toString()); |
|
|
|
state.putInfo("url", url.toString()); |
|
|
|
} catch (AmazonServiceException ase) { |
|
|
|
/* |
|
|
|
logger.warn("Caught an AmazonServiceException, which " + |
|
|
|
"means your request made it " + |
|
|
|
"to Amazon S3, but was rejected with an error response" + |
|
|
|
" for some reason."); |
|
|
|
logger.warn(ase.getMessage()); |
|
|
|
*/ |
|
|
|
} catch (AmazonClientException ace) { |
|
|
|
/* |
|
|
|
logger.warn("Caught an AmazonClientException, which " + |
|
|
|
"means the client encountered " + |
|
|
|
"an internal error while trying to " + |
|
|
|
"communicate with S3, " + |
|
|
|
"such as not being able to access the network."); |
|
|
|
logger.warn("Error Message: " + ace.getMessage()); |
|
|
|
*/ |
|
|
|
} catch (IOException ioe) { |
|
|
|
//logger.warn("Caught an IOException: " + ioe.getMessage()); |
|
|
|
logger.warn("Caught an IOException: " + ioe.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|