Browse Source

QFX-5192 update:更新版本号,修复一个key存在但是length不一样时会导致写入失败的问题

master
Seth.Tian 4 years ago
parent
commit
42110ac049
  1. 2
      plugin.xml
  2. 16
      src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java

2
plugin.xml

@ -5,7 +5,7 @@
<main-package>com.fanruan.fs</main-package>
<active>yes</active>
<hidden>no</hidden>
<version>2.0</version>
<version>2.2</version>
<env-version>10.0</env-version>
<jartime>2020-01-27</jartime>
<vendor>richie</vendor>

16
src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java

@ -28,7 +28,7 @@ import com.fr.workspace.resource.ResourceIOException;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
@ -40,6 +40,7 @@ import java.util.List;
public class S3ResourceRepository extends BaseResourceRepository {
private static final String DELIMITER = "/";
private static final String CHAR_SET = "UTF-8";
private final AmazonS3 s3;
private final String bucket;
@ -162,18 +163,7 @@ public class S3ResourceRepository extends BaseResourceRepository {
@Override
public void write(String path, byte[] data) {
ObjectMetadata metadata;
try {
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);
s3.putObject(bucket, path, new String(data, Charset.forName(CHAR_SET)));
}

Loading…
Cancel
Save