|
|
|
@ -15,16 +15,16 @@ import com.amazonaws.services.s3.model.PutObjectRequest;
|
|
|
|
|
import com.amazonaws.services.s3.model.S3Object; |
|
|
|
|
import com.amazonaws.services.s3.model.S3ObjectSummary; |
|
|
|
|
import com.fanruan.api.log.LogKit; |
|
|
|
|
import com.fanruan.api.util.StringKit; |
|
|
|
|
import com.fr.io.repository.FineFileEntry; |
|
|
|
|
import com.fr.io.repository.base.BaseResourceRepository; |
|
|
|
|
import com.fr.stable.Filter; |
|
|
|
|
import com.fr.workspace.resource.ResourceIOException; |
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.InputStream; |
|
|
|
|
import java.net.URL; |
|
|
|
|
import java.nio.file.Paths; |
|
|
|
|
import java.net.URLConnection; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
@ -124,11 +124,16 @@ public class S3ResourceRepository extends BaseResourceRepository {
|
|
|
|
|
metadata = s3.getObjectMetadata(bucket, path); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
metadata = new ObjectMetadata(); |
|
|
|
|
String mimeType = URLConnection.guessContentTypeFromName(path); |
|
|
|
|
if (mimeType != null) { |
|
|
|
|
metadata.setContentType(mimeType); |
|
|
|
|
} |
|
|
|
|
metadata.setContentLength(data.length); |
|
|
|
|
} |
|
|
|
|
s3.putObject(bucket, path, new ByteArrayInputStream(data), metadata); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean createFile(String path) { |
|
|
|
|
PutObjectRequest request = new PutObjectRequest(bucket, path, new ByteArrayInputStream(new byte[0]), new ObjectMetadata()); |
|
|
|
@ -207,7 +212,19 @@ public class S3ResourceRepository extends BaseResourceRepository {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean isDirectory(String path) { |
|
|
|
|
return path.endsWith(DELIMITER); |
|
|
|
|
if (path.endsWith(DELIMITER)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
ObjectListing listing = s3.listObjects(bucket, path); |
|
|
|
|
if (listing.getObjectSummaries().isEmpty()) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
if (listing.getObjectSummaries().size() > 1) { |
|
|
|
|
return true; |
|
|
|
|
} else { |
|
|
|
|
S3ObjectSummary summary = listing.getObjectSummaries().get(0); |
|
|
|
|
return !StringKit.equals(listing.getPrefix(), summary.getKey()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|