Browse Source

QFX-5192 update:写入的方法回退,改为修改metadata的length

master^2
Seth.Tian 4 years ago
parent
commit
7317ba5d24
  1. 18
      src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java

18
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.nio.charset.Charset;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
@ -163,7 +163,21 @@ public class S3ResourceRepository extends BaseResourceRepository {
@Override
public void write(String path, byte[] data) {
s3.putObject(bucket, path, new String(data, Charset.forName(CHAR_SET)));
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);
}
if (metadata != null) {
metadata.setContentLength(data.length);
}
s3.putObject(bucket, path, new ByteArrayInputStream(data), metadata);
}

Loading…
Cancel
Save